Redirect doesn' t work in BeforeAction

I’m using an ActionFilter to prevent an error under a condition, this in the beforeAction event, I try to do a redirect, but it doesn’t work. What I don’t understand is that in the end the filter lets the Action of the controller pass ignoring the Redirect.

 class ActionIsIdentidadFilter extends ActionFilter
                                                              {
                  public function beforeAction($action)
                    {
                                          if(1==1) //Only for this example
                                     return $this->owner->redirect(['/site/no-identity']);
                                     // I've tried with Yii::$app->getResponse()->redirect(['/site/no-identity']);
                                return parent::beforeAction($action);
    
                                     }

                }

I answer to myself Sorry.
The solution was to put the send () method at the end

                 return $this->owner->redirect(['/site/no-identity'])->send();
1 Like

public function beforeAction($action) should return a bool.

Correct way to do this:

public function beforeAction($action) {
  $this->owner->redirect(['/site/no-identity']);
  return false;
}
1 Like