3
我是symfony 2中的noop。有人可以幫助我獲得symfony2表單類型構建器嗎?Symfony2表單構建器實體類型選定的值
我有一個表單0123'實體,我想在表單中使用selectbox來列出我的User
實體中的所有用戶。當我使用Product
創建表格時,所有輸入均可用,沒有userid
。用戶選擇框未選擇來自Product
實體的值userId
。
namespace ATL\ProductBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\EntityRepository;
class ProductGeneralType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options){
$builder->add("name", null, array(
"label" => "Name",
"required" => true,
"attr" => array(
"class" => "span5",
)
))->add("description",null,array(
"label" => "Description",
"required" => true,
"attr" => array(
"class" => "span8"
)
))->add("visible",null,array(
"label" => "Visible"
))->add("userId","entity",array(
"label" => "User",
"class" => "ATLUserBundle:User",
"query_builder" => function(EntityRepository $er){
return $er->createQueryBuilder("u")->where("u.enabled = 1")->orderBy("u.username", "ASC");
},
));
}
public function getName(){
return "product";
}
public function setDefaultOptions(OptionsResolverInterface $resolver){
$resolver->setDefaults(array(
"data_class" => "ATL\ProductBundle\Entity\Product"
));
}
}
Name
,Description
和Visible
都ok,並從數據庫中獲取。但User
沒有從Product
實體中選擇userId
。有人可以幫我弄這個嗎?