我安装了 GregwarCaptcha 包并在控制器中添加了以下代码
$form = $this->createFormBuilder()
->add('captcha', 'captcha', array(
'width' => 200,
'height' => 50,
'length' => 6,
));
return $this->render('MyIndexBundle:Default:contact.html.twig',array(
'form' => $form->createView()
));
模板中的以下代码
{% form_theme form 'MyIndexBundle:Default:captcha.html.twig' %}
<form action="" method="post">
........
{{ form_widget(form.captcha) }}
.......
</form>
captcha.html.twig 是
{% block captcha_widget %}
{% spaceless %}
<img src="{{ captcha_code }}" alt="" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" />
...
{{ form_widget(form, {'attr': { 'autocapitalize': 'off','autocorrect': 'off' }}) }}
...
{% endspaceless %}
{% endblock %}
我收到“对象“Symfony\Component\Form\FormView”不存在的“方法“验证码”错误。...如果我使用 captcha.html.twig,我直接得到验证码不存在...