在 CodeIgniter 中整合 Discuz X2.5, 引用超級變數 $_G 來獲取用戶名, uid等資訊.
<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
/**
* Discuz! 的用戶數據全部存儲在 UCenter 中,
* 並可以使用 UCenter 的接口體系與第三方產品進行掛接。
* 因此,瞭解 UCenter 也是瞭解 Discuz! 產品體系的重要一步。
*
* @link http://dev.discuz.org/wiki/index.php
* @link http://dev.discuz.org/wiki/index.php?title=UCenter接口
*/
class Discuzx {
public function __construct() {
// $this->CI =& get_instance();
// parent::__construct();
define( 'UC_CONNECT', 'mysql' );
define( 'UC_DBHOST', 'UC_DBHOST' );
define( 'UC_DBUSER', 'UC_DBUSER' );
define( 'UC_DBPW', 'UC_DBPW' );
define( 'UC_DBNAME', 'UC_DBNAME' );
define( 'UC_DBCHARSET', 'utf8' );
define( 'UC_DBTABLEPRE', '`UC_DBNAME`.pre_ucenter_' );
define( 'UC_DBCONNECT', '0' );
define( 'UC_KEY', '123456' );
define( 'UC_API', 'http://apple.com/' );
define( 'UC_CHARSET', 'utf-8' );
define( 'UC_IP', '' );
define( 'UC_APPID', '1' );
define( 'UC_PPP', '20' );
require_once FCPATH . 'bbs/uc_client/client.php';
require_once FCPATH . 'bbs/source/class/class_core.php';
$this->discuz =& discuz_core::instance();
$this->discuz->init_cron = false;
$this->discuz->init_session = false;
$this->discuz->init();
$this->_G = $this->discuz->var;
// $this->_G['uid']
// $this->_G['username']
// $this->_G['adminid']
// $this->_G['groupid']
print_r( uc_get_user( $this->_G['username'] ) );
}
}
//