【问题标题】:How to decorate 'Errors' using standard decorators?如何使用标准装饰器装饰“错误”?
【发布时间】:2010-03-02 15:13:56
【问题描述】:

我是这样设置表单装饰器的:

    <?php

    $this->setElementDecorators(array(
            'Label',
            array(array('labelTd' => 'HtmlTag'), array('tag' => 'td', 'class' => 'name')),
            array(array('elemTdOpen' => 'HtmlTag'), array('tag' => 'td', 'class' => 'form','openOnly' => true, 'placement' => 'append')),
            'ViewHelper',               
            'Errors',           
            array(array('elemTdClose' => 'HtmlTag'), array('tag' => 'td', 'closeOnly' => true, 'placement' => 'append')),
            array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => 'question')),
    ));

    $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',
            array('HtmlTag', array('tag' => 'table', 'class' => 'simpleform')),
            'Form'
        ));

它输出一个简单的表格

<table class="simpleform">
<tbody>
    <tr class="question">
        <td class="name">
            <label class="required" for="email">Your email</label>
        </td>
        <td class="form">
            <input type="text" value="asasd" id="email" name="email">
            <ul class="errors">
                <li>'asasd' is no valid email address in the basic format local-part@hostname
                </li>
                <li>Information not found
                </li>
            </ul>
        </td>
    </tr>
    <tr>
        <td class="element"></td>
        <td class="element">
            <input type="submit" value="Send" id="submit" name="submit">
        </td>
    </tr>
</tbody>
</table>

我想将 ul.errors 包装到 TD 并将其作为第三个单元格。 像这样:

        <tr class="question">
        <td class="name">
            <label class="required" for="email">Your email</label>
        </td>
        <td class="form">
            <input type="text" value="asasd" id="email" name="email">
        </td>
        <td>
            <ul class="errors">
                <li>'asasd' is no valid email address in the basic format local-part@hostname
                </li>
                <li>Information not found
                </li>
            </ul>
        </td>
    </tr>

还有.. 怎么做? :)

【问题讨论】:

  • 嗨,我需要一个相同的代码,如果您可以创建错误装饰器,请在此处显示您的代码
  • 对不起,ulduz114。我不能:(

标签: php zend-framework zend-form zend-decorators


【解决方案1】:

我建议您创建自己的错误装饰器来满足您的需求。
例如,您可以将其设置为输出

    </td>
    <td>
        <ul class="errors">
            <li>'asasd' is no valid email address in the basic format local-part@hostname
            </li>
            <li>Information not found
            </li>
        </ul>

如果您知道错误将始终是&lt;td&gt;&lt;/td&gt; 标记内的表的一部分。

一般来说,没有任何框架足够灵活,可以涵盖所有场景,并且框架不应拖慢您的开发速度。如果您无法使用框架做某事并且您无法扩展框架以满足您的要求,请绕过它并且不要在这种特殊情况下使用它。并不是说所有表格都必须使用Zend_Form :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-15
    • 2013-06-08
    • 1970-01-01
    • 2021-07-19
    • 2013-05-07
    • 1970-01-01
    • 1970-01-01
    • 2011-09-03
    相关资源
    最近更新 更多