(Your login verification may be different from my version, so you will use the appropriate script to meet your needs. I will only tell you what I mean) step: 1. add the $ user attribute to the UserIdentity class. Add the property above the getUser () method-getter. Add the setUser ($ user) method-the property above setter, which can be assigned to the user information through the $ user
I found a better solution.
(Your login verification may be different from my version, so you will use the appropriate script to meet your needs. I only tell you what I mean)
Step: 1. add the $ user attribute to the UserIdentity class. Add the property above the getUser () method-getter. Add the setUser ($ user) method-the property above setter, which can be assigned to the user information through the $ user attribute.
Example of my UserIdentity class:
errorCode=self::ERROR_PASSWORD_INVALID; $user=User::model()->findByAttributes(array('email'=>CHtml::encode($this->username))); if ($user) { if ($user->password === md5($user->salt.$this->password)) { $this->errorCode=self::ERROR_NONE; $this->setUser($user); } } unset($user); return !$this->errorCode; } public function getUser() { return $this->user; } public function setUser(CActiveRecord $user) { $this->user=$user->attributes; } } ?>
Now that the user's attributes have been set, create a WebUser class and put it in/protected/components
hasState('__userInfo')) { $user=$this->getState('__userInfo',array()); if (isset($user[$name])) { return $user[$name]; } } return parent::__get($name); } public function login($identity, $duration) { $this->setState('__userInfo', $identity->getUser()); parent::login($identity, $duration); } } ?>
Remember to set this Yii: app ()-> user
array( 'user'=>array( 'class'=>'WebUser', ) ) ?>
Now you can use the user attribute to access columns in the user database.