Using an example I found in a blog, I set some additional info into the session from the UserIdentity class (UserIdentity.php) like:
class UserIdentity extends CUserIdentity
{
public function authenticate()
{
$user = FcarcUsers::model()->findByAttributes(array('username'=>$this->username));
if($user==null) {
$this->errorCode=self::ERROR_USERNAME_INVALID;
} else if ($user->password != SHA1($this->password) ) {
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
$this->errorCode=self::ERROR_NONE;
// Store the role in a session:
$this->setState('role', $user->admin);
$this->setState('memberId', $user->memberId);
return !$this->errorCode;
}
}
Now I’m off looking to use it from my Controller code and from the docs thought it might be in:
$user=Yii::app()->user;
But that’s not right. When I do a $x = print_r($user,true);
and dump $x to a file, the contents are:
Data is CWebUser Object
(
[allowAutoLogin] =>
[guestName] => Guest
[loginUrl] => Array
(
[0] => /site/login
)
[identityCookie] =>
[autoRenewCookie] =>
[_keyPrefix:private] => 263a04385f19a402ba04178d35f766e3
[_access:private] => Array
(
)
[behaviors] => Array
(
)
[_initialized:private] => 1
[_e:private] =>
[_m:private] =>
)
From my reading, the object (CWebUser) is right, but there’s nothing interesting in it. I am definitely logged in, since the title bar has a “logout(jim)” menu item. When I’m not logged in that reads “login”.
So what’t the secret to getting to my session information? Did I not put it in the right place?
Thanks,
Jim.