Where is the user data?

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) {


                        } else if ($user->password != SHA1($this->password) ) {




                // 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:


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?



Have you read the documentation for setState - http://www.yiiframework.com/doc/api/CWebUser#setState-detail

to get values you set with setState() you can use getState()

The data is in the session… check $_SESSION global array in PHP

I searched the site for setState and didn’t find it but it was a long list and I didn’t read every hit. Thanks for the pointer to the api, that’ll help.


No problem…

If you have javascript enabled in your browser the API documentation has an autocomplete searc field, so it’s very easy to find whatever you need…