我正在使用symfony 4,并且尝试使用集合类型以便能够添加相同实体的许多对象。我遵循了本指南,但收到以下错误:
Key "prototype" for array with keys "value, attr, form, id, name, full_name, disabled, label, label_format, multipart, block_prefixes, unique_block_prefix, translation_domain, cache_key, errors, valid, data, required, size, label_attr, compound, method, action, submitted, sonata_admin_enabled, sonata_help, sonata_admin, horizontal_label_class, horizontal_label_offset_class, horizontal_input_wrapper_class" does not exist.
实际上,当我打印数组时,'prototype'键不存在,类似的问题here并没有帮助我。我收到同样的错误。 到目前为止,这是我尝试过的:
ApplicationType.php
$builder->add('previousjobs', CollectionType::class, array(
'entry_type' => WorkExperienceType::class,
'allow_add' => true,
'prototype' => true,
'prototype_data' => 'New Tag Placeholder',
))
Application.php
public $previousjobs;
public function getPreviousjobs()
{
return $this->previousjobs;
}
form.html.twig
<ul class="tags">
{# iterate over each existing tag and render its only field: name #}
{% for tag in form.previousjobs %}
{# {{ dump(tag.vars.name)|e }} #}
{# {{ form_widget(tag.vars.name)|e }} #}
{# {{form_row(tag.vars.name)}} #}
{# {{ dump(tag)}} #}
{% endfor %}
</ul>
{{ form_end(form) }}
<ul class="tags" data-prototype="{{ form_widget(form.previousjobs.vars.prototype)|e('html_attr') }}">
...
</ul>
非常感谢任何帮助。