0

*我英语说得不好。所以我现在要发布代码。*

表格代码:

protected $elementDecorators = array('ViewHelper','Errors','Description','Label',
            array('HtmlTag',array('tag' => 'div','class' => '_wrapperElement')          
            ));

    public function init(){
        $this->addElement('text','mytext',array(
        'class' => '_inputText',
        'label' => 'Mytext',
        'required' => true,
        'decorators' => $this->elementDecorators
        ));

        $this->setDecorators(array('FormElements',array('HtmlTag',array('tag' => 'div','class' => '_formWrapper')),'Form'));

    }

输出:

<form method="post" action="" enctype="application/x-www-form-urlencoded">
    <div class="_formWrapper">
        <div class="_wrapperElement">
            <label class="required" for="mytext">Mytext</label>
            <input type="text" class="_inputText" value="" id="mytext" name="mytext">    
        </div>
    </div>
</form>

现在我想要一个 div 包装标签和输入元素,如下所示:

<form method="post" action="" enctype="application/x-www-form-urlencoded">
    <div class="_formWrapper">
        <div class="_wrapperElement">
            <div class="_wrapperLabel">
                <label class="required" for="mytext">Mytext</label>
            </div>
            <div class="_wrapperInput">
                <input type="text" class="_inputText" value="" id="mytext" name="mytext">    
            </div>
        </div>
    </div>
</form>

怎么做?

我尝试了很多次,但我做不到。

谢谢!

4

2 回答 2

1
protected $elementDecorators = array('ViewHelper','Errors','Description', array('Label', array('tag' => 'div', 'class' => '_wrapperLabel')
        ),
            array('HtmlTag',array('tag' => 'div','class' => '_wrapperInput')          
            ));
于 2013-03-24T18:28:23.393 回答
0

我找到了将装饰器渲染到 ViewScript 的解决方案。

于 2013-03-24T18:03:46.417 回答