2

实际上,我尝试在中间实体上创建一个表单,并且我想为同一实体显示许多输入(项目颜色和项目名称)。我也可以创建项目实体。

# MyNiceBundle/Form/Type/CollaborationType.php

public function buildForm(FormBuilder $builder, array $options)
{
    $builder->add('project', 'entity', array(
        'class' => 'MyNiceBundle:Project',
        'property' => 'name'
    ));
    $builder->add('project', 'entity', array(
        'class' => 'MyNiceBundle:Project',
        'property' => 'color'
    ));
    $builder->add('participant', 'entity', array(
        'class' => 'MyNiceBundle:User',
        'property' => 'email',
        'multiple' => true,
        'expanded' => true
    ));
    $builder->add('workgroup', 'entity', array(
        'class' => 'MyNiceBundle:Workgroup',
        'property' => 'name',
        'multiple' => false,
        'expanded' => true
    ));
}


# Resources/Views/project_form.html.twig

<form id="project-creation" class="form" action="{{ path('nicebundle_project_create') }}" method="post">
    {{ form_errors(form) }}
    <div class="project">
    # Here I want to show the input for project name
    {{ form_errors(form.project) }}
    {{ form_widget(form.project) }}
    </div>

    <div id="navigation-panel">
        # Here I want to show the input for project color
        {{ form_errors(form.project) }}
        {{ form_widget(form.project) }}

        {{ form_errors(form.participant) }}
        {{ form_widget(form.workgroup) }}
        {{ form_widget(form._token) }}
        <input class="btn" type="reset" value="reset" />
        <input class="btn" type="submit" value="submit" />
    </div>
</form>

我应该怎么办?

提前致谢。

4

1 回答 1

0

我像这样在 CollaborationType 中传递了 ProjectType:

# MyNiceBundle/Form/Type/CollaborationType.php
public function buildForm(FormBuilder $builder, array $options)
{
    $builder->add('project', new ProjectType());
    $builder->add('participant', 'entity', array(
        'class' => 'BtaskUserBundle:User',
        'property' => 'email',
        'multiple' => false,
        'expanded' => true
    ));
    $builder->add('workgroup', 'entity', array(
        'class' => 'BtaskBoardBundle:Workgroup',
        'property' => 'name',
        'multiple' => false,
        'expanded' => true
    ));
}

# Resources/Views/project_form.html.twig
<form id="workgroup-form-create" class="form" action="{{ path('MyNiceBundle_project_create') }}" method="post" {{ form_enctype(form) }}>
    {{ form_errors(form) }}
    <div class="project">
    {{ form_errors(form.project) }}
    {{ form_widget(form.project) }}
    </div>

    <div id="navigation-panel">
        {{ form_errors(form.project) }}
        {{ form_widget(form.project) }}

        {{ form_errors(form.participant) }}
        {{ form_widget(form.participant) }}

        {{ form_errors(form.workgroup) }}
        {{ form_widget(form.workgroup) }}

        {{ form_widget(form._token) }}
        <input class="btn" type="reset" value="reset" />
        <input class="btn" type="submit" value="submit" />
    </div>
</form>
于 2012-06-01T14:17:37.823 回答