私はYiiの初心者です。アプリケーション全体で user_id にアクセスしたい。どうすればそれができますか?
class MainController extends Controller {
public function actionInitialize() {
$this->verifyDrupalUserIdentity();
}
private function verifyDrupalUserIdentity() {
new DrupalUserIdentity();
}
}
class DrupalUserIdentity extends CUserIdentity {
public function __construct() {
$this->authenticate();
}
public function authenticate(){
global $base_url;
$base_url = BASE_URL.'CA_Hive';
$currentPath = getcwd();
require_once DRUPAL_ROOT.'/includes/bootstrap.inc';
require_once DRUPAL_ROOT.'/includes/errors.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
chdir($currentPath);
global $user;
$this->username = $user->name;
new DrupalUser();
Yii::app()->user->setDrupalAttributes($user);
}
}
**
- モデル:-
**
class DrupalUser extends CWebUser {
private $_attributes;
private $_browser;
public $user_id;
public function setDrupalAttributes($attributes) {
$this->_attributes = $attributes;
$this->user_id = $this->_attributes->uid;
}
public function getUserId() {
return $this->user_id;
}
}
Yii::app()->user->getUserId();を使用 してMainControllerのユーザー ID にアクセスできるようになりました。
しかし、問題は、SecondControllerの user_id にアクセスできないことです。アクセスしようとすると、null 値が返されます。助けが必要。
セカンドコントローラー
class SecondController extends Controller {
public function getUserDetail() {
// Here i want the user ID
}
}