Answer the question
In order to leave comments, you need to log in
How to leave the user on the current page after authorization?
I collected authorization in the modal, but after clicking it, it jumps to the main one, but I would like to leave it on the current one.
In theory, goBack should return, but ...
How can this be done in Yii2?
Controller:
public function actionAjaxLogin() {
if (Yii::$app->request->isAjax) {
$login = new LoginForm();
if ($login->load(Yii::$app->request->post())) {
if ($login->login()) {
return $this->goBack();
} else {
Yii::$app->response->format = yii\web\Response::FORMAT_JSON;
return \yii\widgets\ActiveForm::validate($login);
}
}
} else {
throw new HttpException(404 ,'Page not found');
}
}
Answer the question
In order to leave comments, you need to log in
return $this->redirect(Yii::$app->request->referrer)
Yii::$app->request->referrer
may be a completely non-obvious url in it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question