【问题标题】:Subscript or Superscript text within a Zend Form labelZend Form 标签中的下标或上标文本
【发布时间】:2010-03-18 22:01:17
【问题描述】:

我想在 Zend_Form_Element 的标签中包含下标文本,但它似乎不起作用:

 $zend_form_element->setLabel('Label <sub>x</sub>');

我可以做些什么来使其正确输出而无需在视图页面上手动编写表单?感谢您的帮助,

戴夫

【问题讨论】:

    标签: html zend-framework label zend-form


    【解决方案1】:

    我想说最好的方法是从元素中获取实际的装饰器,然后设置转义选项,而不是添加新的装饰器:

    $zend_form_element->getDecorator('Label')->setOption('escape',false);
    

    【讨论】:

    • 这对我不起作用。没有一个答案对我有用。我为其设置标签的文本总是被转义。这是我的元素代码的样子:pastebin.com/tRV9Rx0p
    • 啊,发现了。 $this->setElementDecorators() 稍后被调用并覆盖了我的所有更改。
    【解决方案2】:

    这是正确的做法:

    $zend_form_element->addDecorator('Label', аrray('escape'=>false));
    

    来自:http://forums.zend.com/viewtopic.php?f=69&t=5706

    【讨论】:

      【解决方案3】:

      试试:

      $zend_form_element->setAttribs( array( 'escape' => false ) )
                        ->setLabel( 'Label <sub>x</sub>' );
      

      或单数:

      $zend_form_element->setAttrib( 'escape', false )
                        ->setLabel( 'Label <sub>x</sub>' );
      

      【讨论】:

      • 这很接近,但显然,您必须将 'escape' => false 放在表单元素的实际装饰器上: $zend_form_element->addDecorator('Label', array('escape'= >假));
      【解决方案4】:

      您也可以通过以下方式进行:

      $radioElement = new Zend_Form_Element_Checkbox('formelement_0');
      $radioElement->setLabel('Do you accept the <a href="#">Terms &amp; Conditions</a>?');
      $radioElement->getDecorator('Label')->setOption('escape', false);
      

      【讨论】:

        【解决方案5】:

        根据@fireeyedboy 的回答,您还可以直接在 Zend_Form 中执行以下操作:

        $this->addElement(
        'radio',
        'name',
        array(
            /* more settings */
            'attribs'   => array(
                'escape' => FALSE
            )
        ));
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-01-23
          • 2015-07-28
          • 1970-01-01
          • 2013-09-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多