Answer the question
In order to leave comments, you need to log in
How to get user->identity variable in view?
Please tell me how to access user->identity variable in view.
It is clear that I can do this in the view:
I can declare the $user variable at the beginning of the view and spin around it
I can throw $user into the view right in the controller:<span> =Yii::$app->user->identity->name</span>
$user = Yii::$app->user->identity;
$user = Yii:$app->user->identity;
return $this->render('master',compact('user'));
Answer the question
In order to leave comments, you need to log in
I'm afraid to upset you, but there is no other way)) For this, there is a special Identity to work with an authorized user.
The only thing I would separate authentication and users. Then you can add your method there and implement this:
public function getName(): string
{
//Здесь ваша проверка
return $this->user ? $this->user->getName() : 'БЕЗ ИМЕНИ!';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question