Zend Framework 2重定向

Гео*_*ков 10 zend-framework2

如何重定向到另一个模块?

return $this->redirect()->toRoute(null, array(
    'module'     => 'othermodule',
    'controller' => 'somecontroller',
    'action'     => 'someaction'
));
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用,任何想法?

Die*_*uzi 27

这是我从Controller重定向到另一条路线的方式:

return $this->redirect()->toRoute('dns-search', array(
    'companyid' => $this->params()->fromRoute('companyid')
));
Run Code Online (Sandbox Code Playgroud)

其中dns-search是我想要重定向到的路由,而companyid是url params.

最后,URL变为/ dns/search/1(例如)

  • 并确保您不要错过该“ return”关键字,因为如果您期望没有它的代码执行会在那里停止,那么可能会发生不好的事情;-) (2认同)

小智 16

重定向的一种简单方法是:

return $this->redirect()->toUrl('YOUR_URL');
Run Code Online (Sandbox Code Playgroud)


Kum*_*arA 6

这是ZF2中的重定向方式:

return $this->redirect()->toRoute('ModuleName',
  array('controller'=>$controllerName,
        'action' => $actionName,
        'params' =>$params));
Run Code Online (Sandbox Code Playgroud)

我希望这可以帮助你.

  • `ModuleName`应该是`RouteName` (5认同)