Search code examples
phpzend-frameworkzend-framework2

How to redirect to Home page (Default page) in zend framework 2?


I'm inside a module named "Authentication". After successful login with this module I want my user to redirect to home page (default page).

I tried the following route paths. But didn't worked.

$redirect = '/' ;
//$redirect = '' ;
//$redirect = null ;

return $this->redirect()->toRoute($redirect);

It generate the following error

Route with name "" not found

Home route is not defined in another module which i don't know. So how do i redirect to home page ?


Solution

  • If you can’t tell what is your home route name, you have at least two options:

    1. Make it configurable — put home route name in your module/application config and retrieve it in the controller.
    2. Just redirect to /:

      return $this->redirect()->toUrl('/');