Zend表单中的addDisplayGroup问题

时间:2010-02-08 07:41:56

标签: php zend-framework zend-form

我的表格与以下代码相同:

public function init(){


  $id=$this->createElement('hidden','cf_id');
  $id->setDecorators($this->elementDecorators);
  $id->setOrder(1);
  $this->addElement($id);

  $firstName=$this->createElement('text','firstName');
  $firstName->setDecorators($this->elementDecorators);
  $firstName->setLabel('name :');
  $firstName->setOrder(2);
  $firstName->setAttrib('class','textbox');
  $firstName->setAttrib('disabled',true);
  $this->addElement($firstName);

  $lastname=$this->createElement('text','family');
  $lastname->setLabel(' family:');
  $lastname->setDecorators($this->elementDecorators);
  $lastname->setOrder(3);
  $lastname->setAttrib('class','textbox');
  $lastname->setAttrib('disabled',true);
  $this->addElement($lastname);


  $this->addElement('button', 'cancel', array(
        'label' => 'Cancel Button',

  'class'=>'button',
        'decorators' => array(
            'ViewHelper',
        ),
    )); 

  $this->addElement('button', 'submit', array(
        'label' => 'Submit Button',

     'class'=>'button',
        'decorators' => array(
            'ViewHelper',
        ),
    )); 

  $this->addDisplayGroup(array('submit', 'cancel',), 'submitButtons', array(
        'order'=>4,
        'decorators' => array(
            'FormElements',
            array('HtmlTag', array('tag' => 'div', 'class' => 'element')),
        ),
    )); 
}

在这种形式中有一些元素和两个按钮。在显示页面中,按钮在其他元素之前显示在上面。

如何将这些按钮放在所有元素的底部?

感谢。

3 个答案:

答案 0 :(得分:2)

Zend通过addElements()方法按元素添加顺序呈现元素。所以,我会像这样添加它们:

$this->addElements(array(all elements you want to appear first in top-down order));
$this->addElements(array(button elements));

然后在视图中使用CSS来操纵它们的位置。

希望有所帮助。

答案 1 :(得分:1)

在其他元素之前添加它们; - )

答案 2 :(得分:0)

将您的其他字段添加到另一个显示组,该显示组在您已有的显示组之前定义。你可能需要调整一些装饰器。