salut mes amis,

j'ai un problème qui bloque mon travail , je sais pas comment le résoudre.
'idée est d'affecter au groupe un seul role séléction par l'administrateur . et un role peut avoir plusieurs groupe (ManyTOOne)
j'ai essayé ce code: le type "groups" est collection
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 ->add('groups', 'entity',array(
                                            //'class' => 'GroupsBundle:Roles',
                                            'class'=> 'MemberShipManagement\GroupsBundle\Entity\Roles',
                                            'choice_label' => 'name_role',
                                          /*  'query_builder' => function(EntityRepository $er)
                                            {
                                             return $er->createQueryBuilder('r')
                                             ->orderBy('r.id', 'ASC');
                                            },*/
                                             'required' => false,
                                             'placeholder' => 'Choisir le role du votre groupe'
                                         )
           )
Mais il affiche le probléme suivant:
Catchable Fatal Error: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given, called in /home/syrine01/Desktop/Project_Console/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 555 and defined
500 Internal Server Error - ContextErrorException
Stack Trace
in vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php at line 48 -
*
* @param array $elements
*/
public function __construct(array $elements = array())
{
$this->elements = $elements;
}


at ErrorHandler ->handleError ('4096', 'Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given, called in /home/syrine01/Desktop/Project_Console/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 555 and defined', '/home/syrine01/Desktop/Project_Console/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php', '48', array())
in vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php at line 48
Aprés un recherhe sur internet , j'ai trouvé que le champ de type "collection" traité d'une autre façon.
Ce type collection contient tous les noms des rôles ( d’après un requête qui affiche les noms des rôles d’après la BD)
voilà le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
->add('groups', 'collection', array('class'  => 'GroupsBundle:Roles',
                                                 'query_builder' => function ($repository)
                                                 {
                                                     return $repository->createQueryBuilder('p')->orderBy('p.name_role', 'ASC');
                                                 },
                                               )
-> Un erreur sera affiché car les options que j'ai ajouté n'existe pas, mais j'ai besoin de faire une requête dedans.
The options "class", "query_builder" do not exist. Defined options are: "action", "allow_add", "allow_delete", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "cascade_validation", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "csrf_token_id", "csrf_token_manager", "data", "data_class", "delete_empty", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "intention", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "max_length", "method", "options", "pattern", "post_max_size_message", "property_path", "prototype", "prototype_name", "read_only", "required", "translation_domain", "trim", "type", "validation_groups", "virtual".
Merci,