0

Zend_Form 有可能有 4 列吗?例子:

<table>
    <tr>
        <td>Element 1 label</td>
        <td>element1</td>
        <td>Element 2 label</td>
        <td>element2</td>
    </tr>
</table>

谢谢。

4

1 回答 1

1

是的!
是你的viewScript Decorator朋友。

//the viewScript
<article class="login">
    <form action="<?php echo $this->element->getAction() ?>"
          method="<?php echo $this->element->getMethod() ?>">
        <table>
            <tr>
                <th>Login</th>
            <tr>
                //renders just the Label decorator
                <td><?php echo $this->element->name->renderLabel() ?></td>
                //renders just the viewHelper decorator
                <td><?php echo $this->element->name->renderViewHelper() ?></td>
            </tr>
            <tr>
                 //renders just the Label decorator
                <td><?php echo $this->element->password->renderLabel() ?></td>
                 //renders just the viewHelper decorator
                <td><?php echo $this->element->password->renderViewHelper() ?></td>
            </tr>
            <tr>
                 //renders the entire element
                <td><?php echo $this->element->submit ?></td>
            </tr>
        </table>
    </form>
</article>

表格

<?php
class Application_Form_Login extends Zend_Form
{

    public function init() {
        $this->setMethod('POST');
        $this->setAction('/index/login');

        /**
         * Set the viewScript decorator
         */
        $this->setDecorators(array(
            array('ViewScript', array(
                    'viewScript' => '_login.phtml'
            ))
        ));

        /**
         * Text element 'name'
         */
        $name = new Zend_Form_Element_Text('name');
        $name->setLabel('Name');
        $name->setAttrib('placeholder', 'Username');
        $name->setOptions(array('size' => 20));

        /**
         * Password element for 'password'
         */
        $password = new Zend_Form_Element_Password('password');
        $password->setLabel('Password');
        $password->setAttrib('placeholder', 'Password');
        $password->setOptions(array('size' => 20));

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Login');

        $this->addElements(array($name, $password, $submit));
    }
}

希望这可以帮助。

于 2012-09-27T14:02:13.360 回答