Yii is really a powerful and bloated framework, simple small projects, or only the background interface calls the project, not recommended.
Today record the use of Yii Cwebuser (Yii::app ()->user->login ()) login;
1. Preparatory work
Official standard practice, add a useridentity.php file to the components, class Useridentity extends Cuseridentity
Inherit the cuseridentity, and then write the validated business process in the Useridentity class (such as which table you are in to check data, fetch data, etc.)
2. Start Login
New a useridentity, passing in parameters, and then executing the validation method
Cases:
$this->_identity=new useridentity ($this->username, $this->password);
$this->_identity->authenticate ();
3. Call Yii::app ()->user->login () to save the data (session)
Calling Yii Component Settings session
Yii::app ()->user->login ($this->_identity, $duration);//$duration, Session expiration time, this method is/framework/web/auth/ cwebuser.php Line 222
$this the->_identity Object GetID (), the GetName () method generally returns the user name, user ID, etc.
The official Cuseridentity class, are all returned user name ($this->username)//This method in/framework/web/auth/cuseridentity line 78
If UID is required, you can rewrite the GetId () method in useridentity, so that when you use Yii::app ()->user->getid (), the UID is called instead of username.
This allows access to the user data in the session via Yii::app ()->user->getid (), Yii::app ()->user->getname ().
If you need to put additional data, rewrite the Getpersistentstates () method in the Cuseridentity class, and return the data you want to save in the form of data.
Here you can go through Yii::app ()->user->getstate (' key '); This form of call, where key is the Getpersistentstates () method return out of the array key.
This article describes a Yii user authentication idea, do not recommend copying any one of the text code. You can do it yourself after reading comprehension. Have basic skill can see/framework/web/auth/cwebuser.php source