confusing about implementing identifyInterface and User class

as default, after initializing the advanced template we have a user model like bellow:




class User extends ActiveRecord implements IdentityInterface

{

    const STATUS_DELETED = 0;

    const STATUS_ACTIVE = 10;

    const ROLE_USER = 10;


    /**

     * @inheritdoc

     */

    public static function tableName()

    {

        return '{{%user}}';

    }


    ....

    ....



this class implements the \web\identifyInterface only

but how use the \web\User class behind the seen?

in the \web\User, described as bellow:

does it mean that \web\User is used by my application without need any setting?

Yii::$app->user is not the same as identity.

mean it does not use \web\User class?

can you explain a little bit more?

thank you

yii\web\User class uses Identity to authenticate user. See class description: http://www.yiiframework.com/doc-2.0/yii-web-user.html

sorry, i cant understand

how my user class use this yii\web\User?

my user class only extends active record and implements identify interface :




class User extends ActiveRecord implements IdentityInterface

.

.

.




It’s the other way around. yii\web\User uses your class according to IdentityInterface.

Your user class don’t use yii\web\User, actually it shouldn’t know about this class.

Yii::$app->user (instance of yii\web\User) use instance of your user class as identity (Yii::$app->user->identity), it could be any class as long as it implements IdentityInterface.

thanks you

you mean by changing this config it could be any other class?




'user' => [

    'identityClass' => 'app\models\User', // User must implement the IdentityInterface

    'enableAutoLogin' => true,

    // 'loginUrl' => ['user/login'],

    // ...

]



yes

yii is a little confusing for me

how can i be a pro in it?

First, you should be a pro in OOP (especially "namespaces" and "traits" in PHP). Read more about the principles behind the scenes of Yii and then, start coding or else, the framework will face you with more and more confusing problems instead of helping you in your projects.