2013-02-12 56 views
3

我使用ZF2並且具有定義了一組元素的形式,然後我呈現在我的PHTML這樣的:ZF2格式化?

<?php 

$form = $this->form; 
$form->prepare(); 

echo $this->form()->openTag($form); 
echo $this->formlabel($form->get('description')); 
echo $this->formRow($form->get('radioButton')); 
echo $this->form()->closeTag(); 

?> 

繪製一個標籤和一個單選按鈕。 我的問題是如何將這些元素設置爲我喜歡的格式?例如,使單選按鈕水平顯示而不是垂直顯示,也許可以更改標籤的位置。

+0

默認視圖助手解析你看到它在你的輸出方式:要麼渲染(通過與視圖中的表單元素屬性進行交互)或創建與您的需求對齊的新視圖助手 – Ocramius 2013-02-12 08:35:21

+0

除了@Ocramius所說的內容,您所說的助手的語法是:'formRow($ element,$ position,$ renderErrors)'。你可以這樣做:'$ this-> formRow($ element,'prepend')'使複選框與標籤一致。 – Sam 2013-02-12 09:21:52

回答

9

沒有什麼能夠阻止你將它們格式化,你可以將這些元素放入列表中,或者根據需要添加任何你想要的樣式的標記。

<?php 
$form = $this->form; 
$form->prepare(); 

echo $this->form()->openTag($form); 
?> 
<ul class="form-list"> 
    <li> 
    <div class="form-control"> 
     <?php echo $this->formlabel($form->get('description')); ?> 
     <?php echo $this->formElementErrors($form->get('description')) ?> 
     <?php echo $this->formElement($form->get('description')); ?> 
    </div> 
    <div class="form-control"> 
     <?php echo $this->formlabel($form->get('radioButton')); ?> 
     <?php echo $this->formElementErrors($form->get('radioButton')) ?> 
     <?php echo $this->formElement($form->get('radioButton')); ?> 
    </div> 
    </li> 
</ul> 
<?php echo $this->form()->closeTag() ?> 

如果你想有過實際的元素控制/輸入自己,你可以做這樣的事情:

<label> 
    <?php echo $form->get('radioButton')->getLabel() ?> 
    <input class="bob" type="radio" 
      name="<?php echo $form->get('radioButton')->getName() ?>" 
      value="<?php echo $form->get('radioButton')->getValue() ?>" 
    /> 
</label>