登录成功后,yii2-app-basic 中 URL 没有变化
After login successfully, URL not changing in yii2-app-basic
登录成功后我要去关于页面。没关系。
但是,URL 没有更改为关于页面。和登录页面一样,但是页面内容是关于页面。
SiteController.php
public function actionLogin()
{
if (!\Yii::$app->user->isGuest)
{
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()))
{
return $this->render('about'); // Here
}
return $this->render('login', [
'model' => $model,
]);
}
URL 等同于 http://localhost/myProject/yii/web/index.php?r=site%2Flogin
。
应该是http://localhost/mylawsuit/yii/web/index.php?r=site%2Fabout
那么,登录后如何修改URL呢?提前致谢。
您应该简单地使用重定向,而不是呈现 about
视图:
return $this->redirect(['about']);
你的答案:
if ($model->load(Yii::$app->request->post()))
{
$this->redirect(['about']); // change here to this
}
你可以在这里使用 Yii::$app->request->referrer
Yii Documentation
你是 rendering
actionLogin
中的 about view
。显然您的 URL
将登录并具有 about view
.
的内容
尝试这样的事情。
public function actionLogin()
{
if (!\Yii::$app->user->isGuest)
{
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()))
{
return $this->redirect('about'); // Change it to redirect
}
return $this->render('login', [
'model' => $model,
]);
}
public function actionAbout()
{
return $this->render('about');
}
希望对您有所帮助!
登录成功后我要去关于页面。没关系。
但是,URL 没有更改为关于页面。和登录页面一样,但是页面内容是关于页面。
SiteController.php
public function actionLogin()
{
if (!\Yii::$app->user->isGuest)
{
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()))
{
return $this->render('about'); // Here
}
return $this->render('login', [
'model' => $model,
]);
}
URL 等同于 http://localhost/myProject/yii/web/index.php?r=site%2Flogin
。
应该是http://localhost/mylawsuit/yii/web/index.php?r=site%2Fabout
那么,登录后如何修改URL呢?提前致谢。
您应该简单地使用重定向,而不是呈现 about
视图:
return $this->redirect(['about']);
你的答案:
if ($model->load(Yii::$app->request->post()))
{
$this->redirect(['about']); // change here to this
}
你可以在这里使用 Yii::$app->request->referrer
Yii Documentation
你是 rendering
actionLogin
中的 about view
。显然您的 URL
将登录并具有 about view
.
尝试这样的事情。
public function actionLogin()
{
if (!\Yii::$app->user->isGuest)
{
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()))
{
return $this->redirect('about'); // Change it to redirect
}
return $this->render('login', [
'model' => $model,
]);
}
public function actionAbout()
{
return $this->render('about');
}
希望对您有所帮助!