為什么在 frontend\controllers\siteController.php中的actionLogin方法中,\Yii::$app->user->isGuest返回為false,而在frontend\views\layouts\main.php中 \Yii::$app->user->isGuest返回為true?
1 回答

四季花海
TA貢獻1811條經驗 獲得超5個贊
既然你說view中\Yii::$app->user->isGuest返回為true,那么說明你的程序能夠正常登陸了, 其實actionLogin這個方法是進了兩次,第一次沒有登陸的時候是返回false,所以才會轉到loginForm,第二次返回true,就回到了home, 并且在view中也返回了true
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('login', [ 'model' => $model, ]); } } |
- 1 回答
- 0 關注
- 508 瀏覽
添加回答
舉報
0/150
提交
取消