5

成功登录后我要去关于页面。没关系。

但是,URL 不会更改为 About Page。与登录页面相同,但页面内容为关于页面。

站点控制器.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。提前致谢。

4

4 回答 4

6

而不是渲染about视图,您应该简单地使用重定向:

return $this->redirect(['about']);
于 2015-10-13T12:00:40.130 回答
1

您的答案:

if ($model->load(Yii::$app->request->post())) 
{
     $this->redirect(['about']); // change here to this
}
于 2015-10-13T12:02:23.493 回答
1

你可以Yii::$app->request->referrer 在这里使用 Yii文档

于 2015-10-13T12:03:04.087 回答
1

你是renderingabout viewactionLogin显然您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');
}

希望它会有所帮助!

于 2015-10-13T12:09:13.390 回答