我是新的,在Zend框架中开发。我对形成装饰器的一些研究,但我想要一些特定的东西。

这就是我想要的:

<table>
<tr>
    <td colspan="2">
        <ul class="errors">
            <li>error</li>
        </ul>
     </td>
</tr>
<tr>
   <td>Label :</td>
   <td>input field</td>
</tr>
<tr>
   <td></td>
   <td>Submit Button</td>
</tr>
</table>
.

我所拥有的是:

   $this->setElementDecorators(array(
        'ViewHelper',
        array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
        array('Label', array('tag' => 'td')),
        array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
    ));

    $submit->setDecorators(array('ViewHelper',
        array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
        array(array('emptyrow' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element', 'placement' => 'PREPEND')),
        array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
    ));

    $this->setDecorators(array(
        'FormElements',
        'Errors'
        array('HtmlTag', array('tag' => 'table')),
        'Form'
    ));
.

但它附带了一个htmlspecialchar警告,UL是空的。

是否有可能修复此问题?

有帮助吗?

解决方案

验证错误与单个输入而不是表单,所以我相信您可能很难使用它仅使用装饰器工作。

我只会在视图脚本中单独呈现各个表单元素,以及验证错误。您需要准备展示自己的错误,并完全摆脱装饰器,只能使用ViewHelper粘贴。然后你可以这样做:

<form method="post">
  <table>
  <tr>
    <td colspan="2"><?php echo $this->errors; ?></td>
  </tr>
  <tr>
    <td><?php echo $this->form->foo->getLabel(); ?></td>
    <td><?php echo $this->form->foo; ?></dt>
  </tr>
  </table>
</form>
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top