user->isGuest;" statement to determine. If the condition is true, it means that the user is not logged in."/> user->isGuest;" statement to determine. If the condition is true, it means that the user is not logged in.">

Home  >  Article  >  PHP Framework  >  How to determine whether to log in using yii

How to determine whether to log in using yii

尚
Original
2019-12-09 17:06:512509browse

How to determine whether to log in using yii

Determine whether the user is logged in: (Recommended learning: yii framework)

In Yii2.0, to determine whether the user is logged in, we use The following code can

Yii::$app->user->isGuest;

Example: If the user is already logged in, directly call the goHome() method

if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}

Get the login username

In yii2.0, get the login For the user name in the status, you can use the following code.

Yii::$app->user->identity->username;

The above is the detailed content of How to determine whether to log in using yii. 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
Previous article:How to install yii2.0Next article:How to install yii2.0