私は現在、このビルドを開始した他の人から引き継いだプロジェクトに取り組んでいます。私が最初にプロジェクトを開始したときは、x.domain.com と y.domain.com という 2 つの異なるサブドメインでしたが、現在は 1 つのドメインに移行していますが、domain.com/x と domain.com/y の 2 つのサイトに移行しています。以前はログイン機能は x サブドメインでしか利用できませんでしたが、今ではユーザーも両方のサイトにログインできるようにしたいと考えています。
各サイトには、xyController を拡張するメイン コントローラー (xController と yController) があります。
x サイトにログインするとすべて問題なく動作しますが、domian.com/y にアクセスするとすぐに
yii:app()->user->isGuest returns true
domain.com/x に戻ると、ログインしています。
PHPSESSID Cookie が両方のサイトで同じである理由がわかりません。
これは、CUserIdentity を拡張する私のクラスです。
class UserIdentity extends CUserIdentity{
private $_id;
public function authenticate(){
$user=User::model()->findByAttributes(array('user_name'=>$this->username));
if($user === null){
$this->errorCode=self::ERROR_USERNAME_INVALID;
}else{
if($this->comparePassword($user, $this->password)){
/** Do some other checks here **/
$this->_id=$user->id;
$this->errorCode=self::ERROR_NONE;
return !$this->errorCode;
}
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
return !$this->errorCode;
}
public function getId(){
return $this->_id;
}
}
ここに構成ファイルの一部があります
'components'=>array(
'user'=>array(
'class'=>'WebUser',
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
...
[編集] 問題が何であるかがわかりました。構成配列の id オプションを両方の構成で同じ値に設定する必要がありました。ID は以前はいずれにも設定されていませんでした