[英]Error url parameter when save form element in zend framework 2
在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'));
是可以的,但是當set params是帶有令牌的user_id =>錯誤時,如何解決?
因為Url視圖助手的第一個參數是路由名稱。 如果要添加一些查詢參數,則可以使用第三個參數( $options
請參閱文檔 )
例:
$url = $this->url('user/resetpassword', [], ['query' => ['user_id' => $user_id]]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.