0
我有一個實體(佈局模板),將有多達10個可配置的側邊欄,這些側邊欄都是同一個實體類型的所有實例。如何在symfony2原則中優化這個實體?
我的解決方案,現在是把它像這樣(下圖)
/**
* @var object BizTV\ContainerManagementBundle\Entity\Container
*
* @ORM\ManyToOne(targetEntity="BizTV\ContainerManagementBundle\Entity\Container")
* @ORM\JoinColumn(name="sidebar1", referencedColumnName="id", nullable=true)
*/
protected $sidebar1;
/**
* @var object BizTV\ContainerManagementBundle\Entity\Container
*
* @ORM\ManyToOne(targetEntity="BizTV\ContainerManagementBundle\Entity\Container")
* @ORM\JoinColumn(name="sidebar2", referencedColumnName="id", nullable=true)
*/
protected $sidebar2;
,但我知道的最好的辦法是將它們存儲在對象的數組(這也不會限制我未來10個側翼)。如果有人能在這裏指出我正確的方向。最難的是我選擇這10個實體的形式。我的方式如上所述對於十個屬性中的每一個都是簡單的下拉菜單。
->add('sidebar1', 'entity', array(
'label' => 'Choose sidebar ',
'empty_value' => 'Not active',
'class' => 'BizTVContainerManagementBundle:Container',
'property' => 'select_label',
'query_builder' => function(EntityRepository $er) use ($company) {
return $er->createQueryBuilder('u')
->where('u.company = :company')
->setParameters(array('company' => $company))
->orderBy('u.name', 'ASC');
},
))
->add('sidebar2', 'entity', array(
'label' => 'Choose sidebar ',
'empty_value' => 'Not active',
'class' => 'BizTVContainerManagementBundle:Container',
'property' => 'select_label',
'query_builder' => function(EntityRepository $er) use ($company) {
return $er->createQueryBuilder('u')
->where('u.company = :company')
->setParameters(array('company' => $company))
->orderBy('u.name', 'ASC');
},
))
再次,我意識到這是遠遠做的最好的方式,但作爲新的Symfony2我真的不知道該怎麼去做。