成功登录后我要去关于Page。没关系。
但是,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,
]);
}
网址与http://localhost/myProject/yii/web/index.php?r=site%2Flogin
相同。
它应该是http://localhost/mylawsuit/yii/web/index.php?r=site%2Fabout
那么,如何在登录后更改URL。提前谢谢。
答案 0 :(得分:6)
您应该只使用重定向,而不是呈现about
视图:
return $this->redirect(['about']);
答案 1 :(得分:1)
你的回答:
if ($model->load(Yii::$app->request->post()))
{
$this->redirect(['about']); // change here to this
}
答案 2 :(得分:1)
您可以在Yii::$app->request->referrer
使用Yii Documentation
答案 3 :(得分:1)
rendering
中的about view
actionLogin
。显然你的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');
}
希望它会有所帮助!