-1

我阅读了许多关于如何在 zend 框架中的表格中制作表格的教程,但不幸的是,它们都没有为我工作,我已经花了很多时间在上面,所以我决定问你们。这是我的代码:

public $elementDecorators = array(
        'ViewHelper',
        'Errors',
        array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'col2')),
        array('Label', array('tag' => 'td','class'=>'taR')),
        array(array('row' => 'HtmlTag'), array('tag' => 'tr','class' => 'rowA')),
);

public function init()
{

    $this->setName('message');

    $message_id = new Zend_Form_Element_Hidden('message_id');
    $message_id->addFilter('Int');

    $message_content = new Zend_Form_Element_Text('message_content');
    $message_content->setLabel('Message')
    ->setRequired(true)
    ->addFilter('StripTags')
    ->addFilter('StringTrim')
    ->addValidator('NotEmpty')
    ->setAttrib('class', 'frmtb');
    $username = new Zend_Form_Element_Text('username');
    $username->setLabel('Name')
    ->setRequired(true)
    ->addFilter('StripTags')
    ->addFilter('StringTrim')
    ->addValidator('NotEmpty')
    ->setAttrib('class', 'frmtb');

    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setAttrib('id', 'submitbutton')
    ->setAttrib('class', 'frmbtn');


    //$this->addElements(array($message_id, $username,$message_content, $submit));
    $this->addElement($username,'username',array('decorators' => $this->elementDecorators));
    $this->addElement($message_content,'message_content',array('decorators' => $this->elementDecorators));
    $this->addElement($submit,'submit',array('decorators' => $this->elementDecorators));
}

你能告诉我我做错了什么吗?

4

1 回答 1

1

好的,所以我很幸运在发布此问题后立即找到了答案。这个关于 Zend 表单装饰器的问题真的很有帮助。

我的代码现在看起来像这样:

public function init()
{


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

    $this->setName('message');

    $message_id = new Zend_Form_Element_Hidden('message_id');
    $message_id->addFilter('Int');

    $message_content = new Zend_Form_Element_Text('message_content');
    $message_content->setLabel('Message')
    ->setRequired(true)
    ->addFilter('StripTags')
    ->addFilter('StringTrim')
    ->addValidator('NotEmpty')
    ->setAttrib('class', 'frmtb');

    $message_content->setDecorators(array(
            'ViewHelper',
            'Errors',
            array(array('data'=>'HtmlTag'),
                    array('tag'=>'td','class'=>'element')),
            array('Label',array('tag'=>'td')),
            array(array('row'=>'HtmlTag'),array('tag'=>'tr')),

    ));

    $username = new Zend_Form_Element_Text('username');
    $username->setLabel('Name')
    ->setRequired(true)
    ->addFilter('StripTags')
    ->addFilter('StringTrim')
    ->addValidator('NotEmpty')
    ->setAttrib('class', 'frmtb');

    $username->setDecorators(array(
            'ViewHelper',
            'Errors',
            array(array('data'=>'HtmlTag'),
                    array('tag'=>'td','class'=>'element')),
            array('Label',array('tag'=>'td')),
            array(array('row'=>'HtmlTag'),array('tag'=>'tr')),

    ));

    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setAttrib('id', 'submitbutton')
    ->setAttrib('class', 'frmbtn');

    $submit->setDecorators(array(
            'ViewHelper',
            'Errors',
            array(array('data'=>'HtmlTag'),
                    array('tag'=>'td','class'=>'element')),
            array('Label',array('tag'=>'td')),
            array(array('row'=>'HtmlTag'),array('tag'=>'tr')),

    ));


    $this->addElements(array($message_id, $username,$message_content, $submit));
}
于 2012-08-05T13:51:07.630 回答