globally change ZF2 form formatting

2019-03-01 06:29发布

I'm building forms from entities

$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>

I want something like

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

Is that possible?

1条回答
聊天终结者
2楼-- · 2019-03-01 07:01

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

In fact the formRow viewHelper has a partial parameter

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

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.

查看更多
登录 后发表回答