在zend框架2中保存表单元素时的错误url参数

时间:2015-01-24 04:55:42

标签: php zend-framework zend-framework2 zend-route

module.config.php

...
'may_terminate' => true,
'child_routes' => array(
   'resetpassword' => array(
      'type' => 'Literal',
      'options' => array(
         'route' => '/reset-password',
         'defaults' => array(
            'controller' => 'User\Controller\Index',
            'action' => 'resetpassword',
          ),
       ),
    ),
)
...

并重置密码.phtml

<?php
    $user_id = 1;
    $token = 'ABCXYZ'
    $form = $this->form;
    $form->prepare();
    $form->setAttribute('action', $this->url('user/resetpassword?user_id='.$user_id.'&token='.$token));
    $form->setAttribute('id', 'reset-password-form');
?>

如果我设置$form->setAttribute('action', $this->url('user/resetpassword'));是正常的,但是设置params是user_id with token =&gt;错误 如何解决?

1 个答案:

答案 0 :(得分:1)

因为Url视图助手的第一个参数是路由名称。如果要添加一些查询参数,可以使用第三个参数($options - see documentation

示例:

$url = $this->url('user/resetpassword', [], ['query' => ['user_id' => $user_id]]);