Yii\web\user is a collectively, for users, no specific instances, can only be managed;
Here the App\models\user is the benchmark;
App\models\user is the model class of mapping data table User, but also implements the interface, Yii\web\identityinterface, why to implement this interface,
is because of the login method in Yii\web\user: $identity in Public Function login (identityinterface $identity, $duration = 0) The type of requirement is identityinterface.
Therefore, in the lognform implementation of the landing when the final call to Yii\web\user method,
Yii\web\user is configured within component components, so yii is used in other code:: $app->user, when you log in, this yii:: $app->user Property has value,
About Yii:: $app Several properties of->user, to view the source code in the Yii\web\user, extract part of the following:
* @propertystring|int$idThe unique identifier forThe user.If`NULL', it means the user is a guest.* the "is read-only.* @property identityinterface|NULL $identityThe identityObjectAssociated with the currently logged-inch* User. `NULL' is returnedifThe user is not a logged in (not authenticated). * @property BOOL$isGuestWhether the CurrentUser is a guest. This property is Read-only.* @propertystring $RETURNURLThe URL that the user should is redirected to after login.Note that the type* of this property differs in getter and setter. see [[Getreturnurl ()]] and [[Setreturnurl ()]] fordetails.** @author Qiang Xue <[email protected]>* @since 2.0*/classUserextendscomponent{
One of the variables behind @property is Yii:: $app->user, you can write code such as:
Yii:: $app->user->id, the return value integer |null integer represents the user ID after logging in, and returns a null representation of the visitor guest;
Yii:: $app->user->identity, the return value implements the Identityinterface type Object |null implements the Identityinterface interface as App\models\user, so here is the app Objects of the \models\user
Yii:: $app->user->isguest, return value true|false True means tourists, false means not tourists
Yii:: $app->user->returnurl, the return value string (string) that jumps to the link before the login interface (as is now understood, not known right or wrong)
Understanding of Yii\web\user in Yii2, and self-built App\models\user (basic version), Frontend\models\user application principle