簡體   English   中英

在zend Framework 2中保存表單元素時出現錯誤的url參數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM