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 に答える