2010-11-29 25 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

この(今だけ1つのlabelオプションで構成さあなたのパラメータの配列、この配列を追加)電子メールフィールドを支援する必要があります

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

そして、同じものはLabelなし - 提出してください。

+0

ありがとうございました。論理:) :) – prostynick

+0

ちょっと、こことほぼ同じです:http://framework.zend.com/manual/en/zend.form.elements.html#zend.form.elements.custom – prostynick

関連する問題