0

このように宣言されたテキスト要素があります:

$name = $this->createElement('text', 'name');
$name->setLabel('imie:');

この要素を装飾して、次のようにレンダリングしたいと思います。

<div class="row">
  <span class="label">
    <label for="name" class="highlight">Name</label>
  </span>
  <span class="formw">
    <input type="text"  id="someid" name="name" class="textfield">
  </span>
</div>

私はそれを適切に機能させることができません。そのためのデコレータの設定を誰かが手伝ってくれませんか?

4

1 に答える 1

0

viewScript デコレータを使用します。

部分 @ `views/scripts/_partial.phtml (好きな名前を付けます)

<form action="<?php echo $this->element->getAction() ?>"
      method="<?php echo $this->element->getMethod() ?>">
    <div class="row">
        <span class="label">
            <?php echo $this->element->name->renderLabel() //render the label for element ?>
        </span>
        <span class="formw">
            <?php echo $this->element->name->renderViewHelper() //render just the input of the element ?>
        </span>
        <?php echo $this->element->submit //render the whole submit element ?>
    </div>
</form>

フォームでデコレータを設定します:

class Application_Form_NewForm extends Zend_Form
{
    public function init() {
        $this->setMethod('POST');
        //set the viewscript decorator
        $this->setDecorators(array(
            array('ViewScript', array(
                    'viewScript' => '_partial.phtml'
            ))
        ));
    //more follows...

今はいつものようにフォームをレンダリングしてください

必要に応じて要素デコレータをいじる必要があるかもしれませんが、これで目標に近づくことができます。

お役に立てれば...

于 2012-08-02T09:27:39.757 に答える