我正试图解决这个问题:
类型" Doctrine \ Common \ Collections \ Collection"," Proxies _CG __ \ MyBundle \ Entity \ MyEntity"的预期参数给定
我尝试了许多没有解决方案的东西。当我尝试这个时,我得到了它:
$userCollection = $this->createForm(new UserCollectionType(), $userEvalClass);
UserCollectionType
class UserCollectionType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('users', 'entity', array(
'label' => 'Evaluateurs',
'empty_value' => '',
'expanded' => false,
'multiple' => true,
'class' => 'EvalFour\UtilisateurBundle\Entity\Utilisateur',
utilisateurs
)
);
}
public function getName()
{
return 'user_collection';
}
}
UserCollection
class UserCollection
{
public $users;
public function __construct($users){
$this->users = $users;
}
public function getUsers(){
return $this->users;
}
}
答案 0 :(得分:5)
在buildForm函数中,设置'multiple' => false,
当您将其设置为true时,它需要一组实体而不仅仅是一个实体。
如果您确实想拥有多个用户,请将'entity'
替换为'collection'