user->isGuest)". If the condition is true, the user is not logged in. If the condition is not true, the user is logged in."/> user->isGuest)". If the condition is true, the user is not logged in. If the condition is not true, the user is logged in.">

Home >PHP Framework >YII >yii2 determines whether the user is logged in

yii2 determines whether the user is logged in

angryTom
angryTomOriginal
2019-11-06 15:44:054182browse

yii2 determines whether the user is logged in

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn