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?
samdark
(Alexander Makarov)
October 19, 2014, 8:54am
2
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
samdark
(Alexander Makarov)
October 19, 2014, 10:44am
4
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
.
.
.
samdark
(Alexander Makarov)
October 20, 2014, 6:58am
6
It’s the other way around. yii\web\User uses your class according to IdentityInterface.
diodac
(Diodac)
October 20, 2014, 7:21am
7
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'],
// ...
]
yii is a little confusing for me
how can i be a pro in it?
MLF
(Mmshfe)
October 22, 2014, 5:57am
11
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.