Search code examples
http-redirectcontrollercakephp-3.0before-filter

Cakephp3 redirect in beforeFilter is not working


When I add the $this->redirect statement inside a beforeFilter of a controller and return afterwards, the redirection is being ignored. When I move the redirect statement inside an action of the controller, it works fine. Does someone has an idea what I am doing wrong?

public function beforeFilter(Event $event) {
    if( true ){ //if a sample condition is true
        return $this->redirect([
            'controller' => 'test',
            'action' => 'action'
        ]);
    }

Solution

  • Since I was returning the response object only from the beforeFilter in the AppController the redirect did not work. For further details check out https://github.com/cakephp/cakephp/issues/6705.