gpt4 book ai didi

forms - Symfony2 形式 : Money Currency Symbol and Displaying in Twig

转载 作者:行者123 更新时间:2023-12-02 09:18:53 24 4
gpt4 key购买 nike

我在 Symfony 中有一个表单,它使用货币字段类型,并将货币设置为 GBP。

当我将表单传递给 twig 时,表单将使用以下方式呈现:

{{ form_row(form.price) }}

这将呈现以下 html:

£<input id="app_product_price" name="app_product[price]" required="required" class="form-control" value="9.95" type="text">

我的目标是尝试获取货币符号,以便我可以使用引导货币字段:

<form class="form-inline">
<div class="form-group">
<label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label>
<div class="input-group">
<div class="input-group-addon">$</div>
<input type="text" class="form-control" id="exampleInputAmount" placeholder="Amount">
<div class="input-group-addon">.00</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Transfer cash</button>
</form>

显然,我需要做一些样式设计。但是,我尝试使用下面的方法获取货币符号,但似乎没有任何文档可以做到这一点。

{{ form_label(form.price) }}

{{ form_widget(form.price) }}

这些似乎都无法获取货币,我也研究过使用 {{ form_widget(form.price.vars.currency) }} ,它只显示错误。

是否有任何已知的方法可以从表单字段中提取货币符号?或者我需要走 Twig Form Theming 的路线吗?

最佳答案

恕我直言,没有特定的方法来获取货币的符号( check the Form Variables Reference )。货币的默认值为:类型:字符串默认值:EUR(对应于 ISO 4217 code )。

所以你可以简单地将货币设置为空,并且不会渲染任何符号:

$builder
->add('price', MoneyType::class, array('currency'=>''));

关于forms - Symfony2 形式 : Money Currency Symbol and Displaying in Twig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31292767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com