After I’ve changed the user table and made a new model,Yii::app()->user->id which is expected to be user_id became username instead.
How to set Yii::app()->user->id to be user_id?
(This is the 4th time i try to post it. Every time i submit this post Chrome would say OOPS, don’t know what’s wrong with this site or it’s just the crazy China great firewall which is now making the Internet a intranet causing trouble)
public function authenticate()
{
$c=new CDbCriteria;
$c->condition="username=:username";
$c->params=array("username"=>$this->username);
$user = User::model()->find($c);
if($user === NULL)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!$user->validatePassword($this->password, $this->username))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else{
$this->_id=$user->id; //Is this line supposed to indicate that Yii::app()->user->id should be id?
$this->username = $user->username;
$this->errorCode=self::ERROR_NONE;
}
return $this->errorCode==self::ERROR_NONE;
}
But Yii::app()->user->id is still a username not a id.
UserIdentity represents the data needed to identity a user.
It contains the authentication method that checks if the provided
data can identity the user.
*/
class UserIdentity extends CUserIdentity
{
private $_id;
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/