Add more info to CWebUser

Hello,

what is the recommended way to add more info to CWebuser.

  1. Extend the CWebuser class ? and using the methods/getters-setters assign values like firsname/lastname.

OR

  1. make entries like this inside the authenticate() method of UserIdentity ?

         $this->setState('FirstName', $users->FIRSTNAME);
    
    
         $this->setState('LastName', $users->LASTNAME);
    

thanks

Arvind

WebUser extends CWebUser

{

// do it you like

}

I recommend you load the user model in your "WebUser" class like

class WebUser extends CWebUser {

public function getModel()


{


    $user = User::model()->findByPk($this->getId());// providing the value returned from getId() is the PK in your user table/model


    return $user;


}

}

you can then access the model like $user = Yii::app()->user->getModel(); for the current user.

if($user!==null)

{

// can access all public user AR methods and attributes eg: $user->firstname, $user->status... etc

}

Hello,

I might sound very dumb, but how come this works ?

I extend the CWebUser class like this

class WebUser extends CWebUser

{

public function Foo();

}

then how come Foo() is available to Yii::app()->user.

Is not Yii::app()->user of type CWebUser ?

We have extended CWebUser, so Foo() should be available to WebUser. So how come its available to Yii::app()->user ?

didn’t you specify the class for the user component in your config to be ‘WebUser’? if you did, then Yii::app()->user will reyurn an instance of WebUser.

aaah yes, now its all clear!!!

how did i miss that one ?

thanks a ton

Arvind

http://www.yiiframework.com/doc/cookbook/60/