Zend framework 仅呈现<;表格>;标签

Zend framework 仅呈现<;表格>;标签,zend-framework,zend-form,Zend Framework,Zend Form,有没有办法只渲染Zend_Form对象的开始标记 print $this->registerForm->renderForm(); 呈现,我只需要 编辑: 在Asley提出可能的解决方案后,我为我的表单类写了这篇文章 public function renderFormOpen() { return str_replace('</form>', '', $this->renderForm()); } public function renderFormC

有没有办法只渲染Zend_Form对象的开始标记

print $this->registerForm->renderForm();
呈现
,我只需要

编辑:

在Asley提出可能的解决方案后,我为我的表单类写了这篇文章

public function renderFormOpen() {
    return str_replace('</form>', '', $this->renderForm());
}

public function renderFormClose() {
    return '</form>';
}
公共函数renderFormOpen(){
返回str_replace(“”,,$this->renderForm());
}
公共函数renderFormClose(){
返回“”;
}
在阅读了ZF库中的代码之后,仍然在寻找ZF的工作方法,尽管我认为没有任何方法。

您可以编写一个自定义表单装饰器,它使用一个自定义视图帮助器,只呈现打开的表单标记。但我认为这太过分了。
只需“硬编码”表单标记,并用视图中表单变量提供的数据填充属性

<!--in your view-template -->
<form action="<?php echo $this->form->getAction() ?>"
      enctype="<?php echo $this->form->getEnctype() ?>"
      method="<?php echo $this->form->getMethod() ?>"
      id="<?php echo $this->form->getId() ?>"
      class="<?php echo $this->form->getAttrib('class') ?>" >

    <!--in case your products are represented as elements -->
    <?php foreach ($this->form->getElements() as $element): ?>
       <?php echo $element ?>
    <?php endforeach; ?>

    <!--in case your products are represented as displayGroups -->
    <?php foreach ($this->form->getDisplayGroups() as $displayGroup): ?>
       <?php echo $displayGroup ?>
    <?php endforeach; ?>

    <!--in case your products are represented as subforms -->
    <?php foreach ($this->form->getSubforms() as $subform): ?>
       <?php echo $subform ?>
    <?php endforeach; ?>

    <!--in case your products are rendered by a view helper -->
    <?php foreach ($this->products as $product): ?>
       <?php echo $this->renderProduct($product) ?>
    <?php endforeach; ?>
</form>


你可以这样做:

echo $this->form->getDecorator('Form')->setElement($this->form)->render(false);

通过将false传递给表单装饰器,可以仅呈现打开的表单标记,如下所示:

<?php echo $this->form->renderForm(false) ?>

这将输出如下内容:

<form id="post" enctype="multipart/form-data" method="post" action="/post">
<form id="post" enctype="multipart/form-data" method="post" action="/simchas/post">Some Text</form>

此外,您还可以将字符串传递给表单装饰器,由表单标记包围,如下所示:

<?php echo $this->form->renderForm('Some Text') ?>

其输出类似于:

<form id="post" enctype="multipart/form-data" method="post" action="/post">
<form id="post" enctype="multipart/form-data" method="post" action="/simchas/post">Some Text</form>
一些文本

希望这有帮助……

我得问问。为什么?如果您想在表单中使用自定义内容,您可以始终实现viewhelper。我知道我可以为自定义元素等实现viewhelper。。我的问题是要添加一个产品列表,每个产品都有一个“数量”输入字段。从DB表中提取产品时,产品的数量会发生变化。而且,如果仅仅依靠定制的装饰师来展示产品,那就太过分了。我还想把productlisting放在一个“盒子”中,这个盒子利用滑动门teqniue,因此包含多个div标签。我已经准备好了一个视图助手来输出这样的框,但是直接从视图而不是从表单。为什么不在表单对象中创建动态字段呢?你知道,只需循环遍历db条目并创建相应的zend_form_元素。我知道这一点,但正如我所写的,我想向客户展示产品的方式需要花费大量的时间来编写装饰程序并让他们按预期工作。Zend_表单很棒,但也有点僵硬,你真的需要了解它的内部工作原理。我认为这是采埃孚最难合作的部分。好。。我可能只是将标记硬编码到viewscript中,然后呈现DisplayGroups。简单的方法是,只需在itRenderForm上进行字符串替换(false),在最新版本的ZF中就不再有效了。在1.9.5版本中对我有效