方法" codigoActividad" for object" Symfony \ Component \ Form \ FormView"不存在add.html.twig

时间:2016-02-01 13:01:43

标签: forms symfony

您好我试图显示来自FormType的字段,该字段位于其中,并且还在实体中,但我仍然收到错误。

  

方法codigoActividad for object" Symfony \ Component \ Form \ FormView"   在...中不存在   AgcBackendBundle:表格:第95行的edit-form-config-actividad.html.twig

我打电话给de createForm:

$form['form'] = $formulario->createView();

模板的第95行是..

 <div class="col-md-6">
                            {{ form_widget(form.form.codigoActividad, { 'attr': {'class' : 'form-control','style': 'font-size:11px;'} }) }} </div>

,建设者是......

$builder
            ->add('nombreActividad',null,array('required' => true))
            ->add('codigoActividad','text')

...

2 个答案:

答案 0 :(得分:0)

form.form。它真奇怪没有?

QGuiApplication app(argc, argv);

QQuickView view;
view.setSource(QUrl("qrc:/main.qml"));
view.show();

QQuickView view2;
view2.setSource(QUrl("qrc:/main2.qml"));
view2.show();

return app.exec();

试试这个

<div class="col-md-6">
                            {{ form_widget(form.form.codigoActividad, { 'attr': {'class' : 'form-control','style': 'font-size:11px;'} }) }} </div>

答案 1 :(得分:0)

这是一种非常奇怪的方式,你如何渲染两种形式...也许你可以尝试单独创建它们,只需在传递到树枝时指定一个名称:

$formBuilderOne = $this->container
                ->get('form.factory')
                ->createNamedBuilder('formOne', 'form', NULL, array('validation_groups' => array()))
                ->add('name', 'text')
                ->add('submit', 'submit');

        // get form from form builder
        $formOne = $formBuilderOne
                ->getForm()
                ->handleRequest($request);

        // build form
        $formBuilderTwo = $this->container
                ->get('form.factory')
                ->createNamedBuilder('formTwo', 'form', NULL, array('validation_groups' => array()))
                ->add('name', 'text')
                ->add('submit', 'submit');

    // get form from form builder
    $formTwo = $formBuilderTwo
            ->getForm()
            ->handleRequest($request);

    return array(
        'formOne' => $formOne->createView(),
        'formTwo' => $formTwo->createView()
    );

如果您使用表单类,则类似这样的内容:

    $formOne = $this->createForm(new FormOneType);

    $formTwo = $this->createForm(new FormTwoType);

所以在树枝上你不需要像form.form.something那样做(甚至不知道是否有效)。然后你做这样的事情:

{{ form_widget(formOne.codigoActividad) }}