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

How to determine whether to log in using yii

Release: 2019-12-09 17:06:51
Original
2557 people have browsed it

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;
Copy after login

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

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

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;
Copy after login

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!

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