php - Symfony3 - FOSUserBundle - Roles attribution -


first of all, i'm french beg pardon poor english.

i come cause here am, i'm starting first symfony3 project ! , got first problem: want use fosuserbundle manage users, dont want visitor able register. want administrator create users (i think can it), need in user creation form, administrator can assign role user. (just 1 role)

here's problem: symfony3 changed lot in point, , solutions found dont match anymore. infact, add field collectiontype in /registration of fosuserbundle , put registration page under /admin/registration making administrators able create new users. change registration redirection make website dont think administrator visitor using form. idea? well, need give me code of "->add('role')" .. please :d. cause it's different used in symfony2.

so, want like:

    // \fos\userbundle\form\type\registrationformtype.php   $builder ->add('roles', collectiontype::class, array(                 'entry_type' => texttype::class,                 'entry_options' => array(                     '/* choices */' => array(                         /*list of roles security.yml*/                     )                 )             ); 

thanks !

you have use choices form type

an example roles in symfony :

in controller

// ... function $user = new user(); $roles = $this->container->getparameter('security.role_hierarchy.roles'); $myform = $this->createform(new usertype($roles), $user);  $builder->add('roles', 'choice', array(         'choices' => $this->flattenarray($this->roles), ));  // ... code  // transform symfony roles 1 dimensional array. public function array_flatten($array) {     if (!is_array($array)) {         return false;     }     $result = array();     foreach ($array $key => $value) {         if (is_array($value)) {             $result = array_merge($result, array_flatten($value));         } else {             $result[$key] = $value;         }     }     return $result; } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -