yii2 Determine whether the user has logged in
Determine whether the user has logged in
if(Yii::$app->user->isGuest){ echo '还没登录,去登录页面'; }else{ echo '已经登录了,去干登录后该干的事'; }
Yii commonly used to obtain login user information
a) Get the controller name
Get the controller name in the controller: $this->getId();
Get the controller name in the view: Yii::app()->controller->id;
b) Get the action name
In the controller beforeAction() callback function Get the action name: $name = $action->id
Get the action name elsewhere: $this->getAction()->getId();
Anywhere Yii ::app()->controller->Action->id;
Get the current user id YII:app()->user->id
Recommended:《 YII Tutorial》
The above is the detailed content of yii2 determines whether the user is logged in. For more information, please follow other related articles on the PHP Chinese website!