A
A
Alexander Stepanov2018-02-26 00:52:29
Yii
Alexander Stepanov, 2018-02-26 00:52:29

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

1 answer(s)
M
Maxim Timofeev, 2018-02-26
@Exebeche

return $this->redirect(Yii::$app->request->referrer)

But you need to make sure that there are no redirects, since there Yii::$app->request->referrermay be a completely non-obvious url in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question