Symfony4细枝模板错误:变量“0”;小部件;不存在

Symfony4细枝模板错误:变量“0”;小部件;不存在,symfony,twig,Symfony,Twig,我在运行时遇到了小树枝错误 我试图找出我犯的错误,但我看不到任何错误。。。也许我看错了文件,但是在这个错误出现之前,我已经试着看了所有我做过更改的地方 这是我的小树枝代码: {% extends 'base.html.twig' %} {% block body %} <div class="container"> {% form_theme form 'bootstrap_4_layout.html.twig' %} {{ form_st

我在运行时遇到了小树枝错误

我试图找出我犯的错误,但我看不到任何错误。。。也许我看错了文件,但是在这个错误出现之前,我已经试着看了所有我做过更改的地方

这是我的小树枝代码:

{% extends 'base.html.twig' %}
{% block body %}
    <div class="container">

        {% form_theme form 'bootstrap_4_layout.html.twig' %}
        {{ form_start(form) }}

        <br>

        Name {{ form_widget(form.name) }}
        Price {{ form_widget(form.price) }}
        Available {{ form_widget(form.available) }}
        Date {{ form_widget(form.date) }}
        <div class="row js-ticket-time-wrapper"
             data-prototype="{{ form_widget(form.times.vars.prototype)|e('html_attr') }}"
             data-index="{{ form.times|length }}">
            {% for time in form.times %}
                <div class="col-xs-4 js-ticket-time-item">
                    <a href="#" class="js-remove-time pull-right">
                        <span class="fa fa-close"></span>
                    </a>
                    {{ form_row(time.name) }}
                </div>
            {% endfor %}
            <a href="#" class="js-ticket-time-add">
                <span class="fa fa-plus-circle"></span>
                Add another Time
            </a>
        </div>
        <button type="submit" class="btn btn-primary" formnovalidate>Save</button>
        {{ form_end(form) }}
    </div>

{% endblock %}
{% block js %}
    {{ parent() }}
    <script>
        jQuery(document).ready(function() {
            var $wrapper = $('.js-ticket-time-wrapper');
            $wrapper.on('click', '.js-remove-time', function(e) {
                e.preventDefault();
                $(this).closest('.js-ticket-time-item')
                    .fadeOut()
                    .remove();
            });
            $wrapper.on('click', '.js-ticket-time-add', function(e) {
                e.preventDefault();
                // Get the data-prototype explained earlier
                var prototype = $wrapper.data('prototype');
                // get the new index
                var index = $wrapper.data('index');
                // Replace '__name__' in the prototype's HTML to
                // instead be a number based on how many items we have
                var newForm = prototype.replace(/__name__/g, index);
                // increase the index with one for the next item
                $wrapper.data('index', index + 1);
                // Display the form in the page before the "new" link
                $(this).before(newForm);
            });
        });
    </script>
{% endblock %}
这是时间类型:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('name', TextType::class);
}

因为formtype
TimeType
的类名与Symfony TimeType()相同,所以formtheme布局会尝试呈现Symfony类型而不是您的类型。您可以看到symfony
TimeType
有一个名为
widget
的选项,因此formtype需要这种类型

因此,请尝试将您的
TimeType
重命名为类似
TicketTimeType
的其他名称

或者,您可以在
TimeType
中像这样重命名块前缀:

public function getBlockPrefix()
{
    return "ticket_time_type";
}

为什么不直接
'entry\u type'=>TextType::class,
?请注意,默认情况下,
TimeType
将使用内置类型的
block time\u小部件
。通过更改类型的名称
MyTimeType
或覆盖块名称,可以解决此问题。
public function getBlockPrefix()
{
    return "ticket_time_type";
}