gpt4 book ai didi

symfony - 如何获取 Twig 中所选 ChoiceType 的值?

转载 作者:行者123 更新时间:2023-12-02 21:07:58 25 4
gpt4 key购买 nike

使用 Symfony 3.3,我已经尝试过类似的操作,但没有响应:

<tr>
{% for choice in form.vars.value.clients %}
<td>{{ choice.value }}</td>
{% endfor %}
</tr>

这是我的表单类型:

$builder->add('name')
->add('contact')
->add('idprofession')
->add('idcard');

我什么也没做,因为对于外键来说,它是默认的一个选择,我想恢复 id professional 的值

最佳答案

您可以使用selectedchoice Twig测试:

<option {% if choice is selectedchoice(value) %} selected="selected"{% endif %} ...>

如上所述here in the doc .

希望这有帮助

关于symfony - 如何获取 Twig 中所选 ChoiceType 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46321656/

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