I am facing the problem with return to previous page, will be very thankful if some help me. This is my controller login action
public function actionLogin() {
$this->layout = 'login';
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,
]);
}
}
when i enter the username and password every things goes right but the user stay in same page(login page.). I also try to render some other view or redirect it to some action but its not working. When i echo something before goBack() function its working fine which means user is login.
You could use
return $this->redirect(Yii::$app->request->referrer);
return $this->goBack((
!empty(Yii::$app->request->referrer) ? Yii::$app->request->referrer : null
));
or
if(Yii::$app->request->referrer){
return $this->redirect(Yii::$app->request->referrer);
}else{
return $this->goHome();
}
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