全局更改 ZF2 表单格式 [英] globally change ZF2 form formatting

查看:22
本文介绍了全局更改 ZF2 表单格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从实体构建表单

$builder = new AnnotationBuilder( $entityManager);
$form = $builder->createForm( $entity );

这是一个很棒的功能(为我节省了很多工作),但我想要的是全局更改这些表单的布局.我想使用表格布局而不是

This is a great feature (saves me a lot of work), but what I want is to globally change the layout of these forms. I want to use a table layout instead of

<label><span>Name:</span><input type="text" value="" name="name"></label>

我想要类似的东西

<tr><td>Name:</td><td><input type="text"></td></tr>

这可能吗?

推荐答案

我实际上误以为您不需要实际扩展或编写新的 viewHelper 来实现不同类型的渲染.

I actually was mistaken you do not need to actually extend or write a new viewHelper to achieve a diffrent kind of rendering.

实际上formRow viewHelper 有一个部分参数

In fact the formRow viewHelper has a partial parameter

public function __invoke(ElementInterface $element = null, $labelPosition = null, $renderErrors = null, $partial = null)

一旦使用该参数集调用 viewHelper <?php echo $this->formRow($element, null, true, 'path/to/your/partial');?> 它将设置以下变量供您使用.

Once the viewHelper is called with that parameter set <?php echo $this->formRow($element, null, true, 'path/to/your/partial'); ?> it'll set following variables for your partial to use.

'element'           => $element,
'label'             => $label,
'labelAttributes'   => $this->labelAttributes,
'labelPosition'     => $this->labelPosition,
'renderErrors'      => $this->renderErrors,

现在您只需编写自己的标记,就可以开始使用了.

Now you'll only have to write your own markup and you should be good to go.

这篇关于全局更改 ZF2 表单格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆