<legend id='dMtE5'><style id='dMtE5'><dir id='dMtE5'><q id='dMtE5'></q></dir></style></legend>

  • <i id='dMtE5'><tr id='dMtE5'><dt id='dMtE5'><q id='dMtE5'><span id='dMtE5'><b id='dMtE5'><form id='dMtE5'><ins id='dMtE5'></ins><ul id='dMtE5'></ul><sub id='dMtE5'></sub></form><legend id='dMtE5'></legend><bdo id='dMtE5'><pre id='dMtE5'><center id='dMtE5'></center></pre></bdo></b><th id='dMtE5'></th></span></q></dt></tr></i><div id='dMtE5'><tfoot id='dMtE5'></tfoot><dl id='dMtE5'><fieldset id='dMtE5'></fieldset></dl></div>
      <bdo id='dMtE5'></bdo><ul id='dMtE5'></ul>

    <tfoot id='dMtE5'></tfoot>

        <small id='dMtE5'></small><noframes id='dMtE5'>

        如何删除 Zend 表单元素上的所有 DtDdWrappers 和标签

        时间:2023-10-03
          • <bdo id='kCU6I'></bdo><ul id='kCU6I'></ul>

            <i id='kCU6I'><tr id='kCU6I'><dt id='kCU6I'><q id='kCU6I'><span id='kCU6I'><b id='kCU6I'><form id='kCU6I'><ins id='kCU6I'></ins><ul id='kCU6I'></ul><sub id='kCU6I'></sub></form><legend id='kCU6I'></legend><bdo id='kCU6I'><pre id='kCU6I'><center id='kCU6I'></center></pre></bdo></b><th id='kCU6I'></th></span></q></dt></tr></i><div id='kCU6I'><tfoot id='kCU6I'></tfoot><dl id='kCU6I'><fieldset id='kCU6I'></fieldset></dl></div>

                <tbody id='kCU6I'></tbody>
              • <small id='kCU6I'></small><noframes id='kCU6I'>

                <tfoot id='kCU6I'></tfoot>
                <legend id='kCU6I'><style id='kCU6I'><dir id='kCU6I'><q id='kCU6I'></q></dir></style></legend>

                1. 本文介绍了如何删除 Zend 表单元素上的所有 DtDdWrappers 和标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我知道我可以像这样从每个元素中单独删除额外的东西

                  I know I can remove the extra stuff from each element individually like so

                  $button ->removeDecorator('DtDdWrapper')
                          ->removeDecorator('HtmlTag')
                       ->removeDecorator('Label');
                  

                  我想知道我是否可以以 zend 形式为我的所有元素实现相同的效果?
                  以及如何删除包装表单的 dl?

                  I was wondering if I can achieve the same for all my elements in a zend form?
                  And how does one remove the dl wrapping the form?

                  推荐答案

                  Markus,这是我使用的一个解决方案,看起来效果很好,希望它适合你.

                  Markus, here is a solution that I use that seems to work well, hopefully it will be suitable for you.

                  首先,为了渲染没有

                  标签的表单,我们需要在表单对象本身上设置装饰器.从扩展 Zend_Form 的类内部,您将调用 Zend_Form->setDecorators() 传递表单装饰器数组.

                  First, in order to render the form with no <dl> tag, we need to set the decorators on form object itself. From inside a class extending Zend_Form, you would call Zend_Form->setDecorators() passing an array of form decorators.

                  来自参考指南:

                  Zend_Form 的默认装饰器是 FormElements、HtmlTag(包装在定义列表中)和 Form;创建它们的等效代码如下:

                    $form->setDecorators(array(
                        'FormElements',
                        array('HtmlTag', array('tag' => 'dl')),
                        'Form'
                    ));
                  

                  要将表单包装在 dl 以外的其他东西中,我们使用上述装饰器,但将 dl 更改为您使用的任何标记,我通常使用 form 类的 div> 我们稍后会看到.

                  To wrap the form in something other than a dl, we use the above decorators but change the dl to whatever tag you use, I typically use a div of class form which we will see later.

                  接下来,需要处理的元素.Zend_Form 元素对不同类型的元素有不同的装饰器.以下各组元素类型都有自己独特的装饰器集:[Submit &按钮]、[验证码]、[文件]、[图像]和[收音机*].radio 的装饰器与标准元素非常相似,只是它没有在标签内指定 for 属性.

                  Next, the elements need to be dealt with. Zend_Form elements have different decorators for different types of elements. The following groups of element types each have their own distinct set of decorators: [Submit & Button], [Captcha], [File], [Image], and [Radio*]. The decorator for radio is very similar to standard elements except that it does not specify the for attribute inside the label.

                  所有其他表单元素、文本、密码、选择、复选框等都使用相同的默认装饰器集.

                  All other form elements, text, password, select, checkbox, etc use the same set of default decorators.

                  要从单个表单元素中删除 dd/dt 标签,我们需要对其应用我们自己的一组装饰器.下面是一个不使用 dd/dt 标签的例子:

                  To remove the dd/dt tags from an individual form element we would need to apply our own set of decorators to it. Here is an example that does not use dd/dt tags:

                  array(
                      'ViewHelper',
                      'Errors',
                      array('Description', array('tag' => 'p', 'class' => 'description')),
                      array('HtmlTag',     array('class' => 'form-div')),
                      array('Label',       array('class' => 'form-label'))
                  );
                  

                  这会将每个表单元素包装在一个带有 form-div 类的 div 标签中.问题是,您必须将这组装饰器应用于您不想包含在 dd/dt 标签中的每个元素,这可能会有点问题.

                  This will wrap each form element in a div tag with the class form-div. The problem is, you have to apply this set of decorators to EVERY element that you don't want to be wrapped in the dd/dt tags which can be a bit problematic.

                  为了解决这个问题,我创建了一个从 Zend_Form 扩展的类,并赋予它一些与 Zend_Form 的默认装饰器不同的默认行为和装饰器.

                  To solve this issue, I create a class that extends from Zend_Form and give it some default behavior and decorators that are different from the default decorators for Zend_Form.

                  虽然我们不能让 Zend_Form 自动将正确的装饰器分配给特定的元素类型(您可以将它们分配给特定的元素名称),但我们可以设置一个默认值,并让我们自己轻松访问一个地方的装饰器,所以如果他们需要改变,他们可以很容易地改变所有形式.

                  While we can't quite have Zend_Form automatically assign the correct decorators to specific element types (you can assign them to specific element names), we can set a default, and give ourselves easy access to the decorators from one place, so if they need to change, they can be easily changed for all forms.

                  这是基类:

                  <?php
                  
                  class Application_Form_Base extends Zend_Form
                  {
                      /** @var array Decorators to use for standard form elements */
                      // these will be applied to our text, password, select, checkbox and radio elements by default
                      public $elementDecorators = array(
                          'ViewHelper',
                          'Errors',
                          array('Description', array('tag' => 'p', 'class' => 'description')),
                          array('HtmlTag',     array('class' => 'form-div')),
                          array('Label',       array('class' => 'form-label', 'requiredSuffix' => '*'))
                      );
                  
                      /** @var array Decorators for File input elements */
                      // these will be used for file elements
                      public $fileDecorators = array(
                          'File',
                          'Errors',
                          array('Description', array('tag' => 'p', 'class' => 'description')),
                          array('HtmlTag',     array('class' => 'form-div')),
                          array('Label',       array('class' => 'form-label', 'requiredSuffix' => '*'))
                      );
                  
                      /** @var array Decorator to use for standard for elements except do not wrap in HtmlTag */
                      // this array gets set up in the constructor 
                      // this can be used if you do not want an element wrapped in a div tag at all
                      public $elementDecoratorsNoTag = array();
                  
                      /** @var array Decorators for button and submit elements */
                      // decorators that will be used for submit and button elements
                      public $buttonDecorators = array(
                          'ViewHelper',
                          array('HtmlTag', array('tag' => 'div', 'class' => 'form-button'))
                      );
                  
                  
                      public function __construct()
                      {
                          // first set up the $elementDecoratorsNoTag decorator, this is a copy of our regular element decorators, but do not get wrapped in a div tag
                          foreach($this->elementDecorators as $decorator) {
                              if (is_array($decorator) && $decorator[0] == 'HtmlTag') {
                                  continue; // skip copying this value to the decorator
                              }
                              $this->elementDecoratorsNoTag[] = $decorator;
                          }
                  
                          // set the decorator for the form itself, this wraps the <form> elements in a div tag instead of a dl tag 
                          $this->setDecorators(array(
                                               'FormElements',
                                               array('HtmlTag', array('tag' => 'div', 'class' => 'form')),
                                               'Form'));
                  
                          // set the default decorators to our element decorators, any elements added to the form
                          // will use these decorators
                          $this->setElementDecorators($this->elementDecorators);
                  
                          parent::__construct();
                          // parent::__construct must be called last because it calls $form->init()
                          // and anything after it is not executed
                      }
                  }
                  
                  /*
                     Zend_Form_Element default decorators:
                     $this->addDecorator('ViewHelper')
                          ->addDecorator('Errors')
                          ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
                          ->addDecorator('HtmlTag', array('tag' => 'dd',
                                                          'id'  => array('callback' => $getId)))
                          ->addDecorator('Label', array('tag' => 'dt'));
                  */
                  

                  现在要使用这个类,从这个基类扩展所有的表单,然后像往常一样分配元素.如果您使用 Zend_Form_Element_XXX 而不是 addElement() 那么您将需要将装饰器之一作为选项传递给元素构造函数,如果您使用 Zend_Form->addElement,然后它将使用我们在类中分配的默认装饰器 $elementDecorators.

                  Now to use the class, extend all of your forms from this base class and go about assigning elements as usual. If you use Zend_Form_Element_XXX as opposed to addElement() then you will need to pass one of the decorators as an option to the element constructor, if you use Zend_Form->addElement, then it will use the default decorator $elementDecorators we assigned in the class.

                  这是一个示例,展示了如何从该类进行扩展:

                  Here is an example that shows how to extend from that class:

                  <?php
                  
                  class Application_Form_Test extends Application_Form_Base
                  {
                      public function init()
                      {
                          // Add a text element, this will automatically use Application_Form_Base->elementDecorators for its decorators
                          $this->addElement('text', 'username', array(
                              'label'      => 'User Name:',
                              'required'   => false,
                              'filters'    => array('StringTrim'),
                          ));
                  
                          // This will not use the correct decorators unless we specify them directly
                          $text2 = new Zend_Form_Element_Text(
                              'text2',
                              array(
                                  'decorators' => $this->elementDecorators, // must give the right decorator
                                  'label' => 'Text 2'
                              )
                          );
                  
                          $this->addElement($text2);
                  
                          // add another element, this also uses $elementDecorators
                          $this->addElement('text', 'email', array(
                              'label'      => 'Email:', 
                              'required'   => false,
                              'filters'    => array('StringTrim', 'StringToLower'), 
                          ));
                  
                          // add a submit button, we don't want to use $elementDecorators, so pass the button decorators instead
                          $this->addElement('submit', 'submit', array(
                              'label' => 'Continue', 
                              'decorators' => $this->buttonDecorators // specify the button decorators
                          ));
                      }
                  }
                  

                  这显示了一种非常有效的方法来摆脱 dd/dt 和 dl 元素并将它们替换为您自己的元素.必须为每个元素指定装饰器有点不方便,而不是能够为特定元素分配装饰器,但这似乎工作得很好.

                  This shows a pretty effective way to get rid of the dd/dt and dl elements and replace them with your own. It is a bit inconvenient to have to specify the decorators for every element, as opposed to being able to assign decorators to specific elements, but this seems to work well.

                  再添加一个我认为您想要做的解决方案,如果您想渲染一个没有标签的元素,只需创建一个新的装饰器并像这样省略标签装饰器:

                  To add one more solution that I think you were looking to do, if you would like to render an element with no label, simply create a new decorator and omit the label decorator from it like this:

                  $elementDecorators = array(
                      'ViewHelper',
                      'Errors',
                      array('Description', array('tag' => 'p', 'class' => 'description')),
                      array('HtmlTag',     array('class' => 'form-div')),
                      // array('Label',       array('class' => 'form-label', 'requiredSuffix' => '*'))
                      // comment out or remove the Label decorator from the element in question
                      // you can do the same for any of the decorators if you don't want them rendered
                  );
                  

                  请随时要求澄清任何事情,希望这能帮助您.

                  Feel free to ask for clarification on anything, hopefully this will help you out.

                  这篇关于如何删除 Zend 表单元素上的所有 DtDdWrappers 和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:检查当前日期是否在两个日期之间 + mysql select 查 下一篇:如何向 Zend Framework 2 添加自定义视图助手

                  相关文章

                  最新文章

                  <tfoot id='po1q7'></tfoot>
                    <bdo id='po1q7'></bdo><ul id='po1q7'></ul>
                  1. <legend id='po1q7'><style id='po1q7'><dir id='po1q7'><q id='po1q7'></q></dir></style></legend>

                      <small id='po1q7'></small><noframes id='po1q7'>

                      <i id='po1q7'><tr id='po1q7'><dt id='po1q7'><q id='po1q7'><span id='po1q7'><b id='po1q7'><form id='po1q7'><ins id='po1q7'></ins><ul id='po1q7'></ul><sub id='po1q7'></sub></form><legend id='po1q7'></legend><bdo id='po1q7'><pre id='po1q7'><center id='po1q7'></center></pre></bdo></b><th id='po1q7'></th></span></q></dt></tr></i><div id='po1q7'><tfoot id='po1q7'></tfoot><dl id='po1q7'><fieldset id='po1q7'></fieldset></dl></div>