我正在尝试将选定的属性添加到我的<option>
标签
{% for product in form.products %}
{# of course this should only done inside a if,
but for testing purpose, it's okay #}
{{ form_widget(product, { 'attr': {'selected': 'selected'} }) }}
{% endfor %}
但是,这不起作用。即使来自 symfony2 文档的完全相同的复制和粘贴也不起作用:http ://symfony.com/doc/current/book/forms.html#rendering-each-field-by-hand
我在 FormType à la 中添加表单元素:
public function buildForm(FormBuilderInterface $builder, array $options) {
parent::buildForm($builder, $options);
$builder
->add('products', 'entity', array('attr' => array('class' => 'choseable input-xlarge'),
'property_path' => false, 'label' => 'form.products.title', 'class' => 'Test\Bundle\Entity\Product', 'choices' => $products, 'multiple' => true, 'empty_value' => 'form.products.placeholder'));
}
$products
在上面的示例中,所有变量 ( ) 都可以。
有问题吗?
我正在使用 Symfony 2.1.9-dev。