Zend framework2 Zend Framework 2重定向
如何重定向到其他模块Zend framework2 Zend Framework 2重定向,zend-framework2,Zend Framework2,如何重定向到其他模块 return $this->redirect()->toRoute(null, array( 'module' => 'othermodule', 'controller' => 'somecontroller', 'action' => 'someaction' )); 这似乎不起作用,有什么想法吗?这就是我如何从控制器重定向到另一条路线的方法: return $this->redirect()
return $this->redirect()->toRoute(null, array(
'module' => 'othermodule',
'controller' => 'somecontroller',
'action' => 'someaction'
));
这似乎不起作用,有什么想法吗?这就是我如何从控制器重定向到另一条路线的方法:
return $this->redirect()->toRoute('dns-search', array(
'companyid' => $this->params()->fromRoute('companyid')
));
其中dns搜索是我要重定向到的路由,companyid是url参数
最后URL变成/dns/search/1(例如)这是ZF2中的重定向方式:
return $this->redirect()->toRoute('ModuleName',
array('controller'=>$controllerName,
'action' => $actionName,
'params' =>$params));
我希望这对您有所帮助。重定向的简单方法之一是:
return $this->redirect()->toUrl('YOUR_URL');
谷歌认为,这个问题与带有锚的zf2重定向相关,所以如果你不介意的话,我会在这里添加答案。我们可以在
toRoute
的第三个参数中使用fragment
选项:
public function doAction(){
return $this->redirect()
->toRoute('chats',
array('action' => 'view',
'id' => $message->getChat()->getId()
),
array('fragment' => 'm' . $message->getId())
);
}
我的路线:
'chats' => array(
'type' => 'segment',
'options' => array(
'route' => '/chats/[:action/][:id/]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Application\Controller\Chats',
'action' => 'index',
),
),
),
因此,用户将被定向到smth,如
/chats/view/12/#m134
如果您正在重定向,请重定向到路由名称。如果您只是想分派另一个操作,请使用forward()助手。请参阅ModuleName
应为RouteName
,并确保您不会错过“return”关键字,因为如果您希望代码执行停止在那里,则可能会发生不好的事情;-)最好的例子,这个有效,那是最好的一个<代码>返回$this->redirect()->toUrl('/makeworld easy?id=thank-you')代码>此解决方案的用途不同:它用于指向其他资源的链接。原则上,这并不重要,但如果你需要一个Zend-ish方法,公认的答案是最好的。