I
I
Ivan Komarov2017-02-06 14:25:39
Yii
Ivan Komarov, 2017-02-06 14:25:39

YII2: Why does $this-redirect return an empty page?

The problem is not in the syntax, since I get the same result even with return $this->goHome();
Well, I tried a bunch of options from Google - the result is the same.
Why can this happen?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Komarov, 2017-02-07
@FreeTibet

I solved the problem.
This behavior (displaying a blank page) is due to the fact that YII2 checks for the presence of a header before redirecting. If there is a header, then the redirect is not performed and an empty page will be returned.
In my case, the reason for the presence of the header was empty lines at the end in the controller file, it was worth removing them and everything worked.

M
Maxim Timofeev, 2017-02-06
@webinar

1. Where do you use the redirect? In the controller I hope?
2. Make sure $this->redirect is preceded by return
2. Try this

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question