Home > other >  About Yii: : $app -> user -> identity can't get the user data problems
About Yii: : $app -> user -> identity can't get the user data problems

Time:03-29

Form the data is stored in the User model, can realize landing and exit functions.
This is the action method
The public function actionLogin ()
{
[' scenario '$model=new User (=& gt;' login ']);
If ($model - & gt; Load (Yii: : $app - & gt; Request - & gt; Post ()) & amp; & $model - & gt; The login ())
{
Return $this - & gt; Render (' entry - confirm, [' model '=& gt; $model]).
}
The else
{
Return $this - & gt; Render (a 'login', [' model '=& gt; $model]).
}
}

Then the method to realize the login User
The public function the login ()
{
if(! $this-> Validate ())
{
return false;
}
$user=Yii: : $app - & gt; The db - & gt; CreateCommand (" select * from the user where the username="username", [' : username '=& gt; $this - & gt; the username]) - & gt; QueryOne ();
If ($user!==null)
{
If ($this - & gt; CheckPassword ($user [' password ']))
{
Return Yii: : $app - & gt; User - & gt; The login (User: : findOne ([' username '=& gt; $this - & gt; the username]), $this - & gt; RememberMe? 3600 * 24 * away);
}
return false;
}
return false;

}

There is a problem, if here with $user=user: : fingOne ([' username '=& gt; $this - & gt; the username]) to obtain objects
Then $user - & gt; Password is null, but email other attributes can get,
Then use Yii: : $app - & gt; User - & gt; Identity - & gt; The username to get the data that is empty, var_dump (ii: : $app - & gt; User - & gt; Identity) :
App \ models \ User Object
(
[username]=& gt;
["]=& gt;
[rememberMe]=& gt;
[_attributes: yii \ db \ BaseActiveRecord: private]=& gt; Array
(
[id]=& gt; 6
[username]=& gt; Raohong
["]=& gt; $2 y $13 $4 lmusps. IbhCfMBikgP6nuA. KmDmOyCqoKlbiOEv08lVhVZfiTbcy
[authkey]=& gt; - l_yYwqmHQPrrkmXSNR097TVV3s4r_VV
[accecctoken]=& gt;
[email]=& gt; 724736528 @qq.com
)

[_oldAttributes: yii \ db \ BaseActiveRecord: private]=& gt; Array
(
[id]=& gt; 6
[username]=& gt; Raohong
["]=& gt; $2 y $13 $4 lmusps. IbhCfMBikgP6nuA. KmDmOyCqoKlbiOEv08lVhVZfiTbcy
[authkey]=& gt; - l_yYwqmHQPrrkmXSNR097TVV3s4r_VV
[accecctoken]=& gt;
[email]=& gt; 724736528 @qq.com
)

[_related: yii \ db \ BaseActiveRecord: private]=& gt; Array
(
)

[_errors: yii/base/Model: private]=& gt;
[_validators: yii/base/Model: private]=& gt;
[_scenario: yii/base/Model: private]=& gt; The default
[_events: yii/base/Component: private]=& gt; Array
(
)

[_behaviors: yii/base/Component: private]=& gt; Array
(
)

)

A bit odd, solving

CodePudding user response:

Could you tell me why will appear this problem, what do I need to solve...

CodePudding user response:

Problem solved,
User model no longer retrieve information forms, with another model to get the data,
How to solve? Look not to understand,

CodePudding user response:

The problem how to end? I also met this problem, can say detailed point?

CodePudding user response:

The problem how to end? I also met this problem, can say detailed point?

CodePudding user response:

Eldest brother you solved?
  • Related