0

安装新的 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)}}
4

1 回答 1

1

嘎嘎,我找到原因了。Symfony 版本的 Bootstrap 与 BrainCrafted/BootstrapBundle 之间存在冲突。

我知道在 Symfony2.6 中添加 Bootstrap 主题可能是为了消除使用 Bootstrap 对外部包的需求,但我仍然想使用 Braincrafted 包的某些部分。因此,我设法使其正常工作以满足我的需要的方法是删除:

//Braincrafter/BootstrapBundle/Resources/config/services/form.xml
    <service id="braincrafted_bootstrap.form.type.money" class="%braincrafted_bootstrap.form.type.money.class%">
        <tag name="form.type" alias="money" />
    </service>
于 2014-12-21T17:55:42.597 回答