0

私は zend の初心者です。私は zendForms を使用しています。フォーム フィールドをグループにグループ化し、フロントエンドでそれらを異なる div に表示したいのですが、保存ボタンにも同じことをしたいのですが、それは可能ですか?

4

1 に答える 1

0

通常、ZF では複数の方法で実行できますが、私が提案する最も簡単な方法は、表示グループを定義し、それらが生成するデフォルトの html がニーズに合っているかどうかを確認することです (表示グループはfieldsetデフォルトでタグ付きでレンダリングされます)。

さらにカスタマイズが必要な場合は、以下を参照してください。

class Form_Product extends Zend_Form
{
    public function init()
    {
        $a = new Zend_Form_Element_Text('a');
        $b = new Zend_Form_Element_Text('b');
        $c = new Zend_Form_Element_Text('c');

        /*
         * The first way is to define display groups and customize their decorators
         */
        $this->addDisplayGroup(array($a, $b), 'groupAB');
        $this->getDisplayGroup('groupAB')->setDisableLoadDefaultDecorators(true);
        $this->getDisplayGroup('groupAB')->setDecorators(array(
            'FormElements',
            'DtDdWrapper'
        )); // or whatever decorators you need

        $this->addDisplayGroup(array($c), 'groupC');
        // ...

        /*
         * Second way is to use custom view script to render the form. 
         * In view use $this->element to get form object 
         * and $this->element->getElements() or $this->element->getElement('name') to get elements
         */
        $this->addElements(array($a, $b, $c));

        $this->setDisableLoadDefaultDecorators(true);
        $this->setDecorators(array(
            array('ViewScript', array('viewScript' => 'controller/action/form.phtml')),
        ));
    }
}
于 2014-02-10T11:10:29.140 に答える