2013-02-28 83 views
0

需要關於如何創建自定義HTML標記(如Zend 1上的表單裝飾器)的教程。 我想產生類似:Zend Form自定義HTML標記

<ul> 
<li> 
    <label class="required"><span>*</span> Username</label> 
    <input id="username" name="username" type="text"> 
</li> 
<li> 
    <label class="required"><span>*</span> Password</label> 
    <input id="password" name="password" type="password"> 
</li> 
</ul> 
+0

你只需要實現自己的視圖助手爲例來處理這種標記。就這麼簡單 :) – Ocramius 2013-02-28 08:48:51

回答

1

假設表單元素被命名爲usernamepassword,這裏會得到所需要的輸出

<?php 
// attributes to apply to label(s) 
$labelAttr = array('class' => 'required'); 
// extra label content (assumes Username and Password are already present in the given elements) 
$labelSpan = '<span>*</span> '; 
// set the label attributes 
$form->get('username')->setLabelAttributes($labelAttr); 
$form->get('password')->setLabelAttributes($labelAttr); 
?> 

<ul> 
<li> 
    // use the formLabel helper, hand it the extra label content, and tell it to place the existing label after it 
    <?php echo $this->formLabel($form->get('username'), $labelSpan, 'append'); 
    <?php echo $this->formInput($form->get('username'); 
</li> 
<li> 
    <?php echo $this->formLabel($form->get('password'), $labelSpan, 'append'); 
    <?php echo $this->formInput($form->get('password'); 
</li> 
</ul>