redirect() does not work, if YII_DEBUG is false

Hello!

In Short:

If I comment out the line below or set the value to false, then I get a blank page, when I use $this->redirect(…)


defined('YII_DEBUG') or define('YII_DEBUG', true);

(this line is in index.php)

In Detail (with some analysis):

I am using $this-redirect($someUrl) in some controller to redirect to another page, if the user has no rights to access the requested page. This works fine in Debug Mode, but not if I comment out the line above.

This problem happens on my local WAMPP (XAMPP on Windows) installation and also online.

I have latest Yii (2.0.2).

I tried to turn on Yii Logging in "Production Mode", but it does not log anything. Then I have checked the Apache Error Log and the Apache Access Log. The Error Log does not write any new log entries when I try to reproduce the problem, but in the Access Log I can see that for the "working case" I get Http Code 302, which is fine, but if YII_DEBUG is false (resp. the line above is commented out), then I get Http Code 500 only, and I get a blank page.

If I call a page which does not have any redirects (for example the login page), then it shows the page and it is working fine.

I also tried to explicitly set the error code like: $this->redirect($someUrl, 302)

Any ideas, where I should continue my analysis? I have no more ideas :(

If you get a blank page, error is in controller.

Show your code.

Hi,

thanks for the hint. You were right :( ;)

The problem was that I did the redirect() in the beforeAction() function of the controller. After this function the action was executed and there I accessed an object, which was not initialized in this case. Now it is handled and it works fine.

-> RESOLVED :)