nếu tôi hiển thị trường "loại thực thể" trong biểu mẫu của tôi và tôi muốn lọc loại đối tượng này dựa trên đối số tôi chuyển từ bộ điều khiển, làm cách nào để thực hiện điều đó ..?chuyển dữ liệu từ bộ điều khiển đến Loại symfony2
//PlumeOptionsType.php
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('framePlume', 'entity', array(
'class' => 'DessinPlumeBundle:PhysicalPlume',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('pp')
->where("pp.profile = :profile")
->orderBy('pp.index', 'ASC')
->setParameter('profile', ????)
;
},
));
}
public function getName()
{
return 'plumeOptions';
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Dessin\PlumeBundle\Entity\PlumeOptions',
'csrf_protection' => true,
'csrf_field_name' => '_token',
// a unique key to help generate the secret token
'intention' => 'plumeOptions_item',
);
}
}
và bên trong bộ điều khiển, tôi tạo ra các hình thức:
i have that argument that i need to pass in my action code:
$profile_id = $this->getRequest()->getSession()->get('profile_id');
...
and then i create my form like this
$form = $this->createForm(new PlumeOptionsType(), $plumeOptions);
các $ plumeOptions chỉ là một lớp học để tồn tại. Nhưng nó có mối quan hệ một-một với một lớp khác gọi là PhysicalPlume. Bây giờ, khi tôi muốn hiển thị 'framePlume' trong mã của tôi, tôi muốn hiển thị một thực thể PhysicalPlume được lọc.
đã trả lời ... kiểm tra http://stackoverflow.com/questions/6716776/symfony-2-how-to-pass-data-to-for mbuilder – xeon