我的表格'Donacion'与'pajuela'OneToMany有关系。 当我用addTagForm添加'Pajuela'时,它被创建,但是如果我提交表单并且我进行转储(公式),则ArrayCollection'pajuelas'为空。
我已阅读官方文档但未发现我的问题... 这是链接:https://symfony.com/doc/3.3/form/form_collections.html
这是我的代码:
# DonacionType
...
case 4:
$builder
->add('pajuelas',CollectionType::class, array(
'entry_type' => PajuelaType::class,
'entry_options' => array(
'tipo_sede' => $options['tipo_sede'],
'sede_id' => $options['sede_id'],
),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
))
->add('observacionesPajuelas', TextareaType::class)
;
break;
...
# PajuelaType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('tipo', ChoiceType::class, array(
'choices' => array(
'Completa' => 'Completa',
'Controles' => 'Controles'
)
))
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Pajuela::class,
'tipo_sede' => null,
'sede_id' => null,
));
}
#Twig:
...
{% form_theme formulario _self %}
{% block _entidadbundle_donacion_pajuelas_entry_widget %}
{% if form is defined %}
{% if form.parent != null %}
<div class="form-group {% if form_errors(form.tipo) %}has-error{% endif %} col-lg-2 col-md-12 col-sm-12">
{% if form_errors(form.tipo) %}
{{ form_label(form.tipo, 'pajuela.tipo' | trans) }}
{{ form_widget(form.tipo, {'attr': {'class': 'form-control error'}}) }}
<label for="{{ form.tipo.vars.id }}"
class="error">{{ form_errors(form.tipo) }}</label>
{% else %}
{{ form_label(form.tipo, 'pajuela.tipo' | trans) }}
{{ form_widget(form.tipo, {'attr': {'class': 'form-control'}}) }}
{% endif %}
</div>
{% endif %}
{% endif %}
{% endblock %}
<div class="pajuelas" data-prototype="{{ form_widget(formulario.pajuelas.vars.prototype)|e('html_attr') }}">
{% for pajuela in formulario.pajuelas %}
<div class="row pajuela pajuela-persitida">{{ form_widget(pajuela) }}</div>
{% endfor %}
</div>
...
我找不到我遇到的问题。