2010-11-29 47 views
0

下面的代碼:如何在Zend Framework中使用現有的裝飾器?

$this->addElement('text', 'email', array(
    'label' => 'Your email address:', 
)); 

$this->addElement('submit', 'submit', array(
    'label' => 'Sign Guestbook', 
)); 

產生下面的HTML:

<form enctype="application/x-www-form-urlencoded" action="" method="post"> 
    <dl class="zend_form"> 
     <dt id="email-label"> 
      <label for="email" class="optional">Your email address:</label> 
     </dt> 
     <dd id="email-element"> 
      <input type="text" name="email" id="email" value="" /> 
     </dd> 

     <dt id="submit-label"> 
      &#160; 
     </dt> 
     <dd id="submit-element"> 
      <input type="submit" name="submit" id="submit" value="Sign Guestbook" /> 
     </dd> 
    </dl> 
</form> 

我知道,我可以寫我自己的裝飾,但我想知道,如何利用現有的裝飾,營造以下HTML :

<form enctype="application/x-www-form-urlencoded" action="" method="post"> 
    <div> 
     <label for="email" class="optional">Your email address:</label> 
     <input type="text" name="email" id="email" value="" class="my_class" /> 
    </div> 

    <div> 
     <input type="submit" name="submit" id="submit" value="Sign Guestbook" class="my_class" /> 
    </div> 
</form> 

沒有<dl/><dt/><dd/>,加入class屬性。

例如,我知道,如何去除環境<dl/>標籤:

$this->addDecorator('FormElements') 
    ->addDecorator('Form'); 

是可能其他變化編寫自定義裝飾?

回答

1

這(附加此陣爲您的參數數組,現在僅由一個標籤選項)應與你的電子郵件領域的幫助:

'class' => 'my_class', 
'decorators' => array(
    'ViewHelper', 
    'Errors', 
    'Label', 
    array('HtmlTag', array('tag' => 'div')) 
) 

而且同樣沒有Label - 提交。

+0

謝謝。似乎邏輯:) – prostynick 2010-11-29 13:52:35

相關問題