【问题标题】:How to put 2 buttons in a row in one Zend_Form如何在一个 Zend_Form 中连续放置 2 个按钮
【发布时间】:2010-10-16 14:49:34
【问题描述】:

我认为在您的 Web 应用程序中拥有具有 编辑删除 按钮。但是采埃孚将一个按钮放在另一个按钮下,这是违反直觉的。 我猜 ViewScript 装饰器可以帮助我完全覆盖按钮 html。

但是如何跨其他形式做到这一点,以避免重复? 可能是我过于复杂了,我应该以某种方式粘贴 html 代码而不是按钮元素对象?

【问题讨论】:

    标签: zend-framework layout zend-form decorator


    【解决方案1】:

    这是我在自己的 Form 类中使用的代码,我的所有表单都继承自该类。主要技巧是仅在按钮本身上使用 ViewHelper 装饰器,并将按钮粘贴在使用 DtDdWrapper 的显示组中,并将按钮包装在 <div class='buttons'> 中以获得额外的样式选项

      protected $_buttons = array();
    
      /**
       * Sets a list of buttons - Buttons will be standard submits, or in the getJson() version
       * they are removed from display - but stuck in the json in the .buttons property
       *
       * $buttons = array('save'=>'Save This Thing', 'cancel'=>'Cancel') as an example
       *
       * @param array $buttons 
       * @return void
       * @author Corey Frang
       */
      public function setButtons($buttons)
      {
        $this->_buttons = $buttons;
        foreach ($buttons as $name => $label)
        {
          $this->addElement('submit', $name, array(
              'label'=>$label,
              'class'=>$name,
              'decorators'=>array('ViewHelper'),
            ));
        }
        $this->addDisplayGroup(array_keys($this->_buttons),'buttons', array(
          'decorators'=>array(
            'FormElements',
            array('HtmlTag', array('tag'=>'div', 'class'=>'buttons')),
            'DtDdWrapper'
          )
        ));
      }
    
      // Example from form::init()
      $this->setButtons(array('save'=>'Save Entry', 'delete'=>'Delete Entry'));
    

    【讨论】:

      【解决方案2】:

      在 Zend 开发者专区阅读本教程:

      Decorators-with-Zend_Form.

      【讨论】:

        【解决方案3】:

        可以在 Form 的构造函数中修改按钮装饰器。 按钮应保留没有 HtmlTag 装饰器,以禁用由于 dt/dd 标记而出现在单独的行上,HtmlTag 装饰器可以像这样删除:

        $buttonobject->setDecorators(array(
            'ViewHelper',
            //array('HtmlTag', array('tag' => 'dd')),
            //array('Label', array('tag' => 'dt')),         
        ));
        

        评论仅用于演示目的。 此外,出于样式目的,按钮可以分组到一个字段集中:

        $this->addDisplayGroup(array('delete','submit'),'buttons');

        可选的site.css代码:

        #fieldset-buttons { border: none; }
        

        【讨论】:

          猜你喜欢
          • 2016-05-22
          • 1970-01-01
          • 2019-07-18
          • 1970-01-01
          • 2011-01-16
          • 2013-06-14
          • 1970-01-01
          • 1970-01-01
          • 2020-01-01
          相关资源
          最近更新 更多