我想將Gregwar Bundle(captcha)添加到我的項目中。我做了這裏所示的所有步驟https://github.com/Gregwar/CaptchaBundle/blob/master/README.mdSymfony 2 Gregwar captcha_code不存在異常
但是,它是拋出「變量」captcha_code「不存在」異常。它是否與形式主題部分錯了?
我想將Gregwar Bundle(captcha)添加到我的項目中。我做了這裏所示的所有步驟https://github.com/Gregwar/CaptchaBundle/blob/master/README.mdSymfony 2 Gregwar captcha_code不存在異常
但是,它是拋出「變量」captcha_code「不存在」異常。它是否與形式主題部分錯了?
使用標籤form_theme
例如:
index.html.twig - 模板,表單, captcha.html.twig - 模板與您的驗證碼
index.html.twig內容:
{% form_theme form 'YourBundle::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 %}
塊captcha_widget必須以外的任何其他塊,例如:
{% block captcha_widget %}
{% set label = label|default('')|trim %}
{% if is_human %}
-
{% else %}
{% spaceless %}
<div class="image">
<img id="{{ image_id }}" src="{{ captcha_code }}" alt="" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" />
{% if reload %}
<script type="text/javascript">
function reload_{{ image_id }}() {
var img = document.getElementById('{{ image_id }}');
img.src = '{{ captcha_code }}?n=' + (new Date()).getTime();
}
</script>
<a class="captcha_reload" onclick="reload_{{ image_id }}(); return false;" href="#">{{ 'Renew'|trans({}, 'gregwar_captcha') }}</a>
{% endif %}
</div>
<div class="">{{ label }}{{ label ? '* :': ''}}{{ form_widget(form) }}</div>
{% endspaceless %}
{% endif %}
{%末端嵌段captcha_widget%}
{%form_theme窗口2 _self%}
{嵌段含量%%} ... {%endblock%}