Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Redirect в initialize и beforeExecuteRoute не работает/Redirect to initalize and beforeExecuteRoute not working

Столкнулся с неожиданным поведением фреймворка. $this->response->redirect('login') отлично работает в action-ах, но не работает в initialize и beforeExecuteRoute. С чем это связано, подскажите plz. И как сделать редирект, не используя header?

Faced with a unexpected framework behavior. $this->response->redirect('login') works fine in actions, but it does not work in initialize and beforeExecuteRoute, What is the reason? Tell me please, and how to make a redirection without headers?


You can make redirections in beforeExecuteRoute this way:

public function beforeExecuteRoute($dispatcher)
        return false;

Or you can use a 'forward' if you don't want to use headers:


Thank you. What accounts for the difference in treatment? And that should work in initialize? Currently in initialize does not work one way.


Initialize is not intended to make redirections, you should use 'initialize' just to initialize the controller environment the first time it is used.