I found that yii can get and echo the user name by this :
echo Yii::app()->user->name;
my question is how can I specify the field in the table user to be bind with the CWebUser::name
I found that yii can get and echo the user name by this :
echo Yii::app()->user->name;
my question is how can I specify the field in the table user to be bind with the CWebUser::name
In your config
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'class'=>'WebUser',
),
WebUser class (example for "email" field from table "user"):
class WebUser extends CWebUser
{
public function getEmail()
{
if(!$this->getState('__email')&&$this->id)
{
$user = User::model()->findByPk($this->id);
$this->setState('__email', $user->email);
}
$state = $this->getState('__email');
return $state;
}
public function login($identity, $duration=0)
{
$this->allowAutoLogin = true;
parent::login($identity, $duration);
$this->id = $identity->id;
if (!$this->isGuest)
{
if($user = User::model()->findByPk($this->id))
{
$this->setState('__email', $user->email);
}
}
}
}
You should write your own UserIdentity component by extending CUserIdentity, and in authenticate() method after user identification declare $this->username = $user->variable;