【发布时间】:2014-01-04 11:47:20
【问题描述】:
我想要一个按父类别(不可选择)分组的选择列表(下拉列表)。 这甚至可能吗?
Example:
- Vehiculs (not selectable)
-- Car (selectable)
-- Boat (selectable)
- Computers (not selectable)
实体类别
/**
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
**/
private $children;
/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
**/
private $parent;
表格:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', 'text',
[
'attr' => ['placeholder' => 'Titel', 'class' => 'form-control', 'autocomplete' => 'off'],
'label' => false
]
)
...
->add('category', 'entity',
[
'property' => 'name',
'class' => '***ArticleBundle:Category',
]
)
;
}
使用上面的代码,我只能得到父母,他们是可选择的。 我想将这些父母的孩子分组(1 个深度),并只让孩子们可选择选项。
【问题讨论】:
标签: symfony doctrine-orm self-reference formbuilder