Мой loginAction находится в модуле user , в application/modules/user/controllers/AuthController.php контроллера application/modules/user/controllers/AuthController.php . Я хочу перенаправить успешный вход в indexAction в application/controllers/IndexController.php . Поэтому у меня есть следующее:
if ($result->isValid()) { $auth->getStorage()->write($adapter->getResultRowObject()); $this->_helper->redirector('index', 'index'); return; }
Когда я сейчас вхожу в систему, я получаю сообщение Message: Invalid controller specified (index) . Я предполагаю, что это связано с тем, что мой логин находится у user модуля, а IndexController – в корневом приложении.
Как я могу это исправить?
У помощника redirector () есть несколько способов перенаправления запроса.
попробуйте это, контроллеры в приложении / контроллерах находятся в модуле «по умолчанию» :
if ($result->isValid()) { $auth->getStorage()->write($adapter->getResultRowObject()); //redirector($action, $controller, $module) $this->_helper->redirector('index', 'index', 'default'); }
Способ, которым я предпочитаю использовать этот помощник, более явный, поэтому мне не нужно помнить значения по умолчанию:
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'); }
и быстрый и грязный метод утилиты:
if ($result->isValid()) { $auth->getStorage()->write($adapter->getResultRowObject()); //_redirect($url); $this->_redirect('/index/index'); }
Надеюсь это поможет