dongzangchui2072
2014-05-15 18:30
浏览 42
已采纳

Zend Framework 2,重定向到路由并将变量传递给新控制器

I implemented a form for placing new orders in Zend Framework 2 and after submitting the form I should redirect to another route and take the orders.id variable in another controller.

I tried using $this->redirect()->toRoute('confirm', array('param'=>$orderId)); but it is not working at all.

Maybe I do not know how to get that parameter in another confirmAction controller.

Please give me some examples. Thank you very much.

图片转代码服务由CSDN问答提供 功能建议

我实现了一个表单,用于在Zend Framework 2中下新订单,在提交表单后,我应该重定向到另一个路由, 在另一个控制器中获取 orders.id 变量。

我尝试使用 $ this-> redirect() - > toRoute('confirm',array('param'=> $ orderId)); 但它根本不起作用。

也许我不知道如何在另一个 confirmAction 控制器中获取该参数。

请举几个例子。 非常感谢你。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duandi1919 2014-05-15 19:49
    已采纳

    1) Since this is a routing issue, show what you have for the route in the module.config.php file. You might not have the "param" constraint configured properly in your config if I had to guess.

    It should look something like this:

    'confirm' => array(
        'type' => 'segment',
        'options' => array(
            'route'       => '/controller_name/confirm[/][:param][/]',
            'constraints' => array(
                'param' => '[0-9]*'
            ),
    
            'defaults' => array(
                '__NAMESPACE__' => 'your_namespace', // ex. Application\Controller
                'action'        => 'confirm', // or whatever action you're calling
                'controller'    => 'controller_name' // ex.
            ),
        ),
    ),
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题