【问题标题】:$_disableLoadDefaultDecorators and ZendX_JQuery$_disableLoadDefaultDecorators 和 ZendX_JQuery
【发布时间】:2012-02-02 14:04:05
【问题描述】:

我使用我的班级来改变我的表格的装饰。 换句话说,而不是调用

Application_Form_Login extends Zend_Form

我用:

Application_Form_Login extends My_Form

在我的“My_Form”类中,我定义了以下内容:

protected $_disableLoadDefaultDecorators = true;
protected $_elementDecorators = array(
   'ViewHelper',
   array(
      'Errors', 
      array(
         'data-icon'=>"alert", 
         'class'=>"ui-body ui-body-e errors"
      )
   ),
   'Label',
   array(
      array(
         'row' => "HtmlTag"
      ), array(
         'tag'=>"div", 
         'data-role'=>"fieldcontain"
      )
   )
);

这在我的常规表单上非常有效。 但是一旦我使用 jQuery 表单:

$this->addElement(new ZendX_JQuery_Form_Element_AutoComplete(
   "ac1",
   array('label' => "Your Address:"))
));

它对它们没有影响,它们仍然使用默认的装饰器进行渲染。 任何想法如何为 jQuery 表单元素全局设置装饰器?

【问题讨论】:

    标签: zend-framework zend-form zend-decorators


    【解决方案1】:

    我已经解决了这个问题。以这种方式定义的任何默认装饰器也适用于任何 ZendX_JQuery_Form_Element

    如果

    1. 元素是在addElement 函数内部创建的。换句话说,不要以这种方式创建元素:

      $this->addElement(new ZendX_JQuery_Form_Element_AutoComplete(
          "address",
          array(
              'label' => "Your Address:"
          )
      ));
      

      你应该这样创建它:

      $this->addElement('AutoComplete', 'address', array(
          'label' => "Your Address:"
      ));
      

      因为addElement 自己创建元素时,会将默认装饰器传递给创建函数。否则,元素将在表单上下文之外创建。

    2. Zend_Form 中没有 AutoComplete 元素。所以,你用来构建表单的类,包括你所有的全局设置和装饰(在我的例子中:"My_Form")应该扩展ZendX_JQuery_Form,而不是Zend_Form
    3. ZendX_JQuery_Form_Element_UiWidget 需要 UiWidgetElement 装饰器。所以我们用 ZendX_JQuery 替换 ViewHelper 装饰器:UiWidgetElement

    【讨论】:

      猜你喜欢
      • 2011-06-20
      • 2011-09-08
      • 1970-01-01
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      • 2011-02-17
      相关资源
      最近更新 更多