如何通过实体属性附加伤害值,形成Symfony2的? [英] How to pass entity atribute value to form Symfony2?

查看:174
本文介绍了如何通过实体属性附加伤害值,形成Symfony2的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单类型:

$builder->add('paises', 'collection', array(
                'options' => array('data_class' =>'Acc\ApssBundle\Entity\Pais'),
                'prototype' => true,
                'type' => new PaisType(),
                ))  ;

如何name属性的类派斯添加到标签的形式??

How to add attribute "name" to the class Pais to the label form ??

在树枝我有:

{%  for pais in form.paises %}

<col>   

    <td>{{ form_label(pais.name)  }}</td>


</col>

{% endfor %}    

非常感谢你!

推荐答案

快速和肮脏的:

这不是一个解决方案,但你也可以同样做的:&LT; TD&GT; {{pais.vars.data.name}}&LT; / TD&GT;

It's not a solution but you could just as well do: <td>{{ pais.vars.data.name }}</td>.

有道:

PaisType 设置的 FormEvent 这样的形式是数据感知的:

Within PaisType setup the FormEvent so form is data-aware:

$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
    $pais = $event->getData();
    $form = $event->getForm();

    # Use concreate data tp construct form field
    $form->add('some_custom_field_with_custom_label', 'text', array('label' => $pais->getName()));
});

希望上述任一帮助;)

Hope either of these help ;)

这篇关于如何通过实体属性附加伤害值,形成Symfony2的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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