安装新的 Symfony2.6 以及集成的 Bootstrao 表单主题后。我现在在渲染 Money 字段时遇到了问题。
一张图片可能比试图描述它更容易。
用于从 Bootstrap_3_layout.html.twig 中呈现字段的代码如下所示:
//Bootstrap_3_layout.html.twig
{% block money_widget -%}
<div class="input-group">
{% set prepend = '{{' == money_pattern[0:2] %}
{% if not prepend %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
{% endif %}
{{- block('form_widget_simple') -}}
{% if prepend %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
{% endif %}
</div>
{%- endblock money_widget %}
渲染的 Html 看起来像这样:
<div class="input-group">
<input type="text" id="cost" name="product[cost]" required="required" class="form-control">
<span class="input-group-addon">{{ tag_start }}€{{ tag_end }} </span>
</div>
在升级到 2.6 之前,这些字段工作得非常好。
我检查了在 php.ini 和 config.yml 中启用了 Intl 扩展,我有以下设置:
//Config.yml
framework:
translator: { fallback: "%locale%" }
default_locale: "%locale%"
//Php.ini
[intl]
intl.default_locale = en_utf8
//forms/ProductType.php
->add('cost', 'money', array(
'currency' => 'EUR',
'label' => 'Cost',
))
//views/show.html.twig
{{ form_row(form.cost)}}