【发布时间】:2013-04-04 17:37:55
【问题描述】:
我安装了 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,我会直接得到验证码不存在...
【问题讨论】:
-
递归不是问题吗?在应该呈现小部件的块中,您调用
form_widget并将表单呈现为参数。
标签: php captcha symfony-2.1