我突然遇到一个问题,我在 Symfony2 网站上收到以下错误:
Variable "form" does not exist in SiteBackendBundle::layout.html.twig at line 2
.
我的 SiteBackendBundle::layout.html.twig 文件如下所示:
{% extends '::base.html.twig' %}
{% form_theme form 'SiteBackendBundle:Form:fields.html.twig' %}
{% block body %}
....
{% endblock %}
我的 SiteBackendBundle:Form:fields.html.twig 看起来像这样:
{% block money_widget %}
{% spaceless %}
{{ block('form_widget_simple') | raw }}
{% endspaceless %}
{% endblock %}
我的 Symfony/forms 的 config.yml 如下所示:
framework:
#esi: ~
translator: { fallback: en }
secret: %secret%
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: %kernel.debug%
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_proxies: ~
session: ~
fragments: ~
这也很奇怪,因为这在我跑之前就起作用了php app/console cache:clear
为什么我无法在不出现此错误的情况下扩展表单?这个确切的方法定义在http://symfony.com/doc/2.2/cookbook/form/form_customization.html#method-2-inside-a-separate-template