Symfony2:不推荐使用 FormView 替换?

2022-01-22 00:00:00 php symfony twig

在版本中

2.3、属性

In versions < 2.3, the attribute

data-prototype="{% filter escape %}{% include 'ManaClientBundle:Member:member_prototype.html.twig' with {'form': form.members.get('prototype')} %}{% endfilter %}"

允许原型显示为一行单元格.当然,在 2.3 中,这一行会产生错误

allowed the prototype to display as a row of cells. In 2.3, of course, this line generates the error

对象SymfonyComponentFormFormView"的方法get"不存在

Method "get" for object "SymfonyComponentFormFormView" does not exist

根据 UPGRADE-2.1.md,不推荐使用 get.它不能被建议的 vars 替换,因为它会产生类似的错误.我怎样才能(容易?)像以前一样在 2.3 中渲染原型?使用

Per UPGRADE-2.1.md, get is deprecated. It cannot be replaced by the suggested vars as it produces a similar error. How can I (easily?) render the prototype as before in 2.3? Using

data-prototype="{{ form_widget(form.members.vars.prototype)|e }}"

无论 config.yml 中 twig:resources:form 的 div 或 table 设置如何,都没有提供有用的解决方案.

does not provide a useful solution regardless of div or table settings for twig:resources:form in config.yml.

<tr id="member-form">
<td><input class="smallform" type="radio" name="household[isHead]" value="__name__"></td>
<td>{{ form_widget(form.include, {'attr': {'class':'smallform'}}) }}</td>
<td>{{ form_widget(form.fname, {'attr': {'class':'smallform'}}) }}</td>
<td>{{ form_widget(form.sname, {'attr': {'class':'smallform'}}) }}</td>
<td>{{ form_widget(form.dob, {'attr': {'class':'smallform'}}) }}</td>
<td>{{ form_widget(form.sex, {'attr': {'class':'smallform'}}) }}</td>
<td>{{ form_widget(form.ethnicity, {'attr': {'class':'smallform'}}) }}</td>
<td><a id="removeTr" class="smallbutton" href="#" onclick="removeTr(this)">Remove</a>

推荐答案

form.members.get('prototype') 替换为 form.members.vars.prototype.

本可以更清楚地知道该怎么做,但找到解决方案的猴子比无限的少.

Could have been a whole lot clearer what to do, but fewer than infinite monkeys found a solution.

相关文章