0

私は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                
          }

}
4

2 に答える 2

0

コードを見せてください。クラスSecondControllerから拡張しましたか? Controllerところで、ここで Drupal とは何ですか?

于 2013-07-05T18:08:38.940 に答える