zend2表单和动作属性

时间:2015-06-05 10:41:34

标签: forms zend-framework2

在我的EditController中我有indexAction:

public function indexAction()
{
    $delete = new DeleteForm();
    $view = new ViewModel(array('delete' => $delete ));
    return $view;
}

和视图

<?php
    $formDelete = $this->delete;
    $formDelete->prepare();        
    $formDelete->setAttribute('action', $this->url(NULL, array('controller'=>'Register', 'action' => 'process')));
?>
<?php echo $this->form()->openTag($formDelete);?>
    <div class="form-group">
        <?=$this->formLabel($formDelete->get('reason')); ?>        
        <?=$this->formElement($formDelete->get('reason'))?>
        <?=$this->formElementErrors($formDelete->get('reason'))?>
    </div>
    <div class="form-group">
        <?=$this->formElement($formDelete->get('delete-button'))?>
    </div>
<?php echo $this->form()->closeTag();?>

尽管我在页面源中将action属性设置为RegisterController和processAction,但我总是看到相同的操作。在setAttribute $ this-&gt; url我可以输入我想要的任何内容,在代码源中始终是

<form method="post" name="deleteForm" enctype="multipart/formdata" action="/App/public/element/edit" id="deleteForm">

1 个答案:

答案 0 :(得分:0)

URL帮助程序的第一个参数应该是您要使用的路由的名称,而不是NULL。通过使用NULL,ZF将重新使用当前路由,我认为这在您的情况下是不正确的。