2012-10-22 28 views
0

我是相當新的Zend Framework,我被卡住了。如何從Zend FormErrors中刪除默認<b></b>標籤

下面的代碼是我的窗體的裝飾的片段設置在那裏我遇到了一個問題:

// prepend errors to top 
$this->setDecorators(
    array(
     'FormElements', 
     'Form', 
     array(
      'FormErrors', 
      array(
       'placement' => Zend_Form_Decorator_Abstract::PREPEND 
      ) 
     ) 
    ) 
); 

當錯誤的觀點,我得到以下渲染:

<ul class="form-errors"> 
     <li> 
      <b>First Name: </b> 
      <ul class="errors"> 
      <li>You forgot to enter your First Name.</li> 
      </ul> 
     </li> 
    </ul> 

如何你是否刪除了所有的html,包括標籤<b>First Name: </b>

+0

http://devzone.zend.com/1240/decorators-with-zend_form/ – hakre

回答

2

只要創建定製的裝飾,嘗試這樣的事情

protected $_errorDecorator = array(
    'markupElementLabelEnd' => '', 
    'markupElementLabelStart' => '', 
    'placement'=>Zend_Form_Decorator_Abstract::PREPEND 
); 

$this->setDecorators(array('FormElements','Form', 
    array('FormErrors', 
    $_errorDecorator))); 
+1

顯示的鏈接手動將是OP和這個網站我想未來的訪客有幫助;) – hakre

+0

我想這就是一開始,但標籤內容「名字:」仍然存在。我想知道如何刪除它 – jlibert

0

我知道我有點遲到了,但因爲這是前5名谷歌的結果,仍然沒有答案,我想我會貢獻。

最好的方法是擴展Zend裝飾器,重載renderLabel方法,添加renderLabels配置選項,然後檢查它是否設置。如果是這樣,請不要調用渲染標籤的父函數。

$form->setDecorators(
    array(
     'FormElements', 
     'Form', 
     array(
      'FormErrors', 
      array(
       'placement' => 'prepend', 
       'renderLabels' => false 
      ) 
     ) 
    ) 
); 

class My_Form_Decorator_FormErrors extends Zend_Form_Decorator_FormErrors 
{ 
    /** 
    * @see Zend_Form_Decorator_FormErrors::renderLabel() 
    */ 
    public function renderLabel(Zend_Form_Element $element, Zend_View_Interface $view) 
    { 
     if ($this->getOption('renderLabels') === false) { 
      return; 
     } 

     return parent::renderLabel($element, $view); 
    } 
}