【问题标题】:Zend_Form table decorators 4 columnsZend_Form 表装饰器 4 列
【发布时间】:2012-09-27 13:52:24
【问题描述】:

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

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

谢谢。

【问题讨论】:

    标签: php zend-framework zend-form


    【解决方案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-04-20
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多