I was going to About Page after Successfully login. It's OK.
But, URL not changing to About Page. It is same as login Page, but the content of page is About Page.
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 is same as http://localhost/myProject/yii/web/index.php?r=site%2Flogin
.
It should be http://localhost/mylawsuit/yii/web/index.php?r=site%2Fabout
So, how to change URL after login.? Thanks in advance.
Instead of rendering about
view, you should simply use a redirection :
return $this->redirect(['about']);
your answer:
if ($model->load(Yii::$app->request->post()))
{
$this->redirect(['about']); // change here to this
}
You can use Yii::$app->request->referrer
here a Yii Documentation
You are rendering
the about view
in actionLogin
. obviously your URL
will be login & have content of about view
.
Try something like this.
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');
}
Hope it will help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With