zend2 表单和动作属性
zend2 forms and action attribute
在我的 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();?>
尽管我在页面源代码中将操作属性设置为 RegisterController 和 processAction,但我总是看到相同的操作。在 setAttribute $this->url 我可以输入任何我想要的,在代码源中总是
<form method="post" name="deleteForm" enctype="multipart/formdata" action="/App/public/element/edit" id="deleteForm">
URL 助手的第一个参数应该是您要使用的路由的名称,而不是 NULL
。通过使用 NULL
,ZF 将退回到使用当前路线,我猜这在您的情况下是不正确的。
在我的 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();?>
尽管我在页面源代码中将操作属性设置为 RegisterController 和 processAction,但我总是看到相同的操作。在 setAttribute $this->url 我可以输入任何我想要的,在代码源中总是
<form method="post" name="deleteForm" enctype="multipart/formdata" action="/App/public/element/edit" id="deleteForm">
URL 助手的第一个参数应该是您要使用的路由的名称,而不是 NULL
。通过使用 NULL
,ZF 将退回到使用当前路线,我猜这在您的情况下是不正确的。