Argument 1 passed to yii \ web \ User :: login () should implement the interface yii \ web \ IdentityInterfac, null

I am trying to create a login api and went to the link https://github.com/yiisoft/yii2/blob/master/docs/guide/security-authentication.md

the above url says:

To log in, you can use the following code:

// find a user identity with the specified username. // note that you may want to check the password if needed $identity = User::findOne(['username' => $username]); // logs in the user Yii::$app->user->login($identity); 

where this line should be added to the controller action or class that implements IdentityInterface.

When adding the specified line to the controller action, but I get the error message Argument 1 passed to yii\web\User::login() must implement interface yii\web\IdentityInterface, null given, called in C:\wamp\www\basic\controllers\MyController.php on line 202 and it is determined where the class that implements the Identity interface is the actual model called Myuser (app \ models \ myuser).

Why does he say that yii\web\User::login() should implement an authentication interface?

And if a way to send published parameters to the login function is added to the Myuser class?

Can someone help me with this?

+5
source share
3 answers

Your User Model Must Implement IdentityInterface

 class User extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface{ ... } 
+2
source
 Yii::$app->getUser()->login($user); var_dump($user); 

Try it, you can get an answer.

I met the same problem with you and solved it. var_dump($user) , you may know

0
source

you can implement more than one interface,

 User extends \yii\db\ActiveRecord implements IdentityInterface, OtherInterface { ... } 
0
source

All Articles