简体   繁体   English

如何覆盖symfony使用的“实体”自定义表单类型

[英]How can i override “entity” custom form type used by symfony

I am making my own custom form type which i extend from entity. 我正在制作自己的自定义表单类型,该类型是我从实体扩展过来的。 like this 像这样

public function getParent()
    {
        return 'entity';
    }

    public function getName()
    {
        return 'gender';
    }

Now in the customform field i display the form with this 现在在customform字段中显示带有

{% for child in form %}
               {{ form_widget(child) }}

So it means , i get the collection of forms based on no. 因此,这意味着我将基于No获得表单的集合。 of entities received from query. 从查询收到的实体数量。

now for each form , i have label , value stored in vars variable. 现在对于每种形式,我都有label , value存储在vars变量中。

Now is there any way that i can store one extra variable like category_id in those vars. 现在有什么方法可以在这些var中存储一个额外的变量,例如category_id。 so that i can have diff value for each child of the form 这样我就可以为表单的每个子项获取diff值

You should implement the buildView method: 您应该实现buildView方法:

public function buildView(FormView $view, FormInterface $form, array $options)
{
    $view->vars = array_replace($view->vars, array(
        'yourfield' => 'yourvalue'
    ));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM