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

yii2 determines whether the user is logged in

angryTom
Release: 2019-11-06 15:44:05
Original
4171 people have browsed it

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 '已经登录了,去干登录后该干的事';
}
Copy after login

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!

Related labels:
yii
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template