0

My loginAction is in a module user, in the controller application/modules/user/controllers/AuthController.php. I want to redirect upon successful login to the indexAction in application/controllers/IndexController.php. So I have this:

if ($result->isValid()) {
            $auth->getStorage()->write($adapter->getResultRowObject());

            $this->_helper->redirector('index', 'index');

            return;
}

When I now login, I get the message Message: Invalid controller specified (index). I guess it is because my login is in the module user, while the IndexController is in the root application.

How can I fix this?

Lanbo
  • 15,118
  • 16
  • 70
  • 147
  • `application/controllers/Index.php` is that a valid controller. It should be like `application/modules/{modulename}/controllers/IndexController.php` – Nandakumar V Dec 08 '12 at 10:04
  • @NandakumarV That was a typo, I corrected it. – Lanbo Dec 08 '12 at 10:07
  • what about module? Are you using both modular and non-modular approach in same application? – Nandakumar V Dec 08 '12 at 10:21
  • Do you mean I shouldn't? I am entirely new to Zend and it seems like I am making mistakes on every single line of code. – Lanbo Dec 08 '12 at 10:26
  • modules in Zf1 are totally optional and you can mix and match with out any issues. – RockyFord Dec 08 '12 at 10:46
  • I am not sure if you should or shouldn't.Actually don't know id it is possible in zend. But it is preferable you don't. There are many sections in zend where if the module is not specified default module (default) will be taken. – Nandakumar V Dec 08 '12 at 10:58
  • @RockyFord so you are saying that we can use both modular and non-modular approach in the same application? How is the routing possible them? – Nandakumar V Dec 08 '12 at 11:00
  • @NandakumarV in ZF1 modules don't really exist. The default filesystem built when using Zend_Tool is for most purposes the 'default' module and will route as such when required. Adding additional 'modules' just works (for the most part). Contrast this with ZF2 where modules are enforced, with application being a module itself. I hope this made some sense. – RockyFord Dec 08 '12 at 11:13
  • that was a bit confusing. I have two controllers `application/modules/{modulename}/controllers/IndexController.php` and `application/controllers/IndexController.php`. To which controller will this redirect to `$this->_helper->redirector('index', 'index', 'default')` – Nandakumar V Dec 08 '12 at 11:38

1 Answers1

4

The redirector() action helper has several methods to redirect the request.

try this, the controllers at application/controllers are in the 'default' module:

if ($result->isValid()) {
    $auth->getStorage()->write($adapter->getResultRowObject());
    //redirector($action, $controller, $module)
    $this->_helper->redirector('index', 'index', 'default');
}

The way I prefer to use this helper is more explicit, so I don't have to remember the defaults:

 if ($result->isValid()) {
        $auth->getStorage()->write($adapter->getResultRowObject());
        //gotoSimple($action, $controller, $module, $params = array())
        $this->getHelper(redirector)->gotoSimple('index', 'index', 'default');
        //or use gotoUrl($url)
        $this->getHelper(redirector)->gotoUrl('/index/index');
        //or use gotoRoute()
        $this->getHelper(redirector)->gotoRoute('action'=>'index', 'controller'=>'index', 'module' => 'default');
    }

and the quick and dirty utility method:

 if ($result->isValid()) {
        $auth->getStorage()->write($adapter->getResultRowObject());
        //_redirect($url);
        $this->_redirect('/index/index');
    }

Hope this helps

RockyFord
  • 8,529
  • 1
  • 15
  • 21