Understanding of Yii\web\user in Yii2, and self-built App\models\user (basic version), Frontend\models\user application principle

Source: Internet
Author: User
Tags yii

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.