Php Twig模板出现ContextErrorException和Twig语法错误-Symfony(FOSUserBundle)
我正在使用Symfony上的FOSUserBundle进行用户注册。我按照要求的步骤继续覆盖模板,如图所示 我遇到了以下错误: ContextErrorException:注意:未定义变量:test 其次是: Twig_Error_语法:在编译“FOSUserBundle:Registration:register_content.html.Twig”中的模板(“注意:未定义变量:test”)时引发异常 以下是有问题的register_content.html.twig:Php Twig模板出现ContextErrorException和Twig语法错误-Symfony(FOSUserBundle),php,symfony,twig,fosuserbundle,Php,Symfony,Twig,Fosuserbundle,我正在使用Symfony上的FOSUserBundle进行用户注册。我按照要求的步骤继续覆盖模板,如图所示 我遇到了以下错误: ContextErrorException:注意:未定义变量:test 其次是: Twig_Error_语法:在编译“FOSUserBundle:Registration:register_content.html.Twig”中的模板(“注意:未定义变量:test”)时引发异常 以下是有问题的register_content.html.twig: {% trans_de
{% trans_default_domain 'FOSUserBundle' %}
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }}
method="POST"
class="fos_user_registration_register">
{{ form_widget(form) }}
<div>
<input type="submit" value="{{ 'registration.submit'|trans }}" />
</div>
</form>
{%trans\u默认\u域'FOSUserBundle'%}
{{form_widget(form)}
注册类型:
<?php
namespace DEA\CourriersBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nom')
->add('prenom')
->add('fonction')
->add('telephone');
}
public function getParent()
{
return 'fos_user_registration';
}
public function getName()
{
return 'app_user_registration';
}
}
我找到了一个解决方案,尽管我不明白它为什么有效
我取下了钥匙
{{ form_enctype(form) }}`
因为某种原因导致了这个错误。也许我的文件编码与此有关?解决方案是将Twig更新到最新版本
出现此错误的原因是Twig中的一个错误,该错误已在Twig 1.21.2中修复:表单类型(表单)在Symfony 2.3中被弃用,并将在Symfony 3.0中删除。您应该改用form_start()。确定吗?听起来像是用“test”字符串检查一些功能,用命令检查:grep-rnw src-e“test”