Php Zend 2重定向,toRoute不工作
为什么Zend 2是这样一个Php Zend 2重定向,toRoute不工作,php,redirect,controller,routes,zend-framework2,Php,Redirect,Controller,Routes,Zend Framework2,为什么Zend 2是这样一个@#(#)(!#@??? 好的,我正试图让一个简单的重定向工作。我有一个名为“listitems”的控制器,它有一个名为“editlistitem”的操作。在用手拉雪橇敲打它几个小时后,我终于让表单工作了,验证工作了,条令工作了,所以我可以保存结果 最后一步是将用户重定向到“showlistitem”操作,该操作包括它后面的id。(完整路由子路径是“listitem/showlistitem/2”,其中2是我要查看的id) 我试过: $this->redirec
@#(#)(!#@???
好的,我正试图让一个简单的重定向工作。我有一个名为“listitems”的控制器,它有一个名为“editlistitem”的操作。在用手拉雪橇敲打它几个小时后,我终于让表单工作了,验证工作了,条令工作了,所以我可以保存结果
最后一步是将用户重定向到“showlistitem”操作,该操作包括它后面的id。(完整路由子路径是“listitem/showlistitem/2”,其中2是我要查看的id)
我试过:
$this->redirect()->toRoute('/listitem/showlistitem/2');
$this->redirect()->toRoute('listitem/showlistitem/2');
$this->redirect()->toRoute('showlistitem/2');
$this->redirect()->toRoute('listitem/showlistitem', array('id' => 2));
$this->redirect()->toRoute('listitem-showlistitem', array('id' => 2));
他们没有一个人在工作!(他们都没有找到返回路线)
到控制器的路由在modules.config.php中,带有到操作的子路由。我可以通过手动键入直接转到url,它工作正常。如何在bleep中让Zend将用户从操作重定向到该路由?由参数。这是它的描述: toRoute(字符串$route=null,数组$params=array(),数组$options=array(),布尔值$reuseMatchedParams=false) 重定向到命名路由,使用提供的
$params
和$options
组合URL
给出这个简单的路由配置示例:
//module.config.php
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Segment',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'index',
'action' => 'index',
),
),
),
'app' => array(
'type' => 'Literal',
'options' => array(
'route' => '/app',
'defaults' => array(
'controller' => 'index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action[/:id]]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id'=>'[0-9]+',
),
),
),
),
),
),
),
此重定向工作:
return $this->redirect()->toRoute('app/default',
array('controller'=>'controller-name', 'action'=>'action-name', 'id'=>$id));
在您的情况下,这将起作用:
return $this->redirect()->toRoute('app/default',
array('controller'=>'listitem', 'action'=>'showlistitem', 'id'=>2));
希望这能有帮助2到最后一个看起来像是正确的语法。如果这个问题不起作用,你能将你的路由配置添加到这个问题中吗?如果你真的想重定向到url,那么使用$this->redirect()->toUrl('/listitem/showlistitem/2');否则使用@blackbishop的答案。这是一个
!@(#(#)(!##-
你救了我的一天