Gregwar验证码错误我安装GregwarCaptcha束和在控制器在模板在symfony中2.1.7
{% form_theme form 'MyIndexBundle:Default:captcha.html.twig' %}
<form action="" method="post">
........
{{ form_widget(form.captcha) }}
.......
</form>
添加以下代码
$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()
));
下面的代码和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,directily我得到captcah码不存在...
是不是递归问题?在应该呈现小部件的块中,您将窗体渲染为参数来调用'form_widget'。 – 2013-03-13 21:45:53