1

User case I'm trying to do, if a user not submit his company details always redirect user to company page.

In appController I have written like below beforeRender method

public function beforeRender(\Cake\Event\EventInterface $event) {
        
        if( !is_null($this->Auth) )
        {   
            if($this->getTable('Users')->hasCompany($this->Auth) == false){
                return $this->redirect(['controller'=>'Companies','action'=>'edit']);
            }
        }

}

Here hasCompany method always return true or false. Here I'm trying to redirect user if hasCompany == false. But problem is like infinite loop browser just reloading.Redirection are not working.

Niloy Rony
  • 602
  • 1
  • 8
  • 23
  • I guess the infinite loops happens because you have your redirect in AppController which always triggers as long your user doesn't have a company. Maybe you should the beforeRender in the controller where the your request goes. and then i would put the redirect in the beforeFilter-hook – Steve Kirsch Mar 05 '23 at 20:49

0 Answers0