2013-02-12 53 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>