Twig 使用Symfony 3在FOSUserBundle注册表上显示下拉式角色

Twig 使用Symfony 3在FOSUserBundle注册表上显示下拉式角色,twig,fosuserbundle,symfony-forms,symfony,Twig,Fosuserbundle,Symfony Forms,Symfony,我正在使用FOSUserBundle实现一个使用组和角色的登录系统。我想在FOSUserBundle的用户注册表上显示一个角色名称(角色:投标人和角色:司机)的下拉列表,新用户可以从中选择要申请的角色,我该怎么做? 这是我的密码: 用户实体 <?php namespace RemovalsUK\UserBundle\Entity; use FOS\UserBundle\Model\User as BaseUser; use Doctrine\ORM\Mapping as ORM; /

我正在使用FOSUserBundle实现一个使用组和角色的登录系统。我想在FOSUserBundle的用户注册表上显示一个角色名称(角色:投标人和角色:司机)的下拉列表,新用户可以从中选择要申请的角色,我该怎么做? 这是我的密码:

用户实体

<?php

namespace RemovalsUK\UserBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity(repositoryClass="RemovalsUK\UserBundle\Repository\UserRepository")
 */
class User extends BaseUser
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
    /**
     * @var ArrayCollection
     * @ORM\ManyToMany(targetEntity="RemovalsUK\UserBundle\Entity\Group")
     * @ORM\JoinTable(name="fos_user_user_group",
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
     * )
     */
    protected $groups;

    /**
     * @var array
     * @ORM\OneToMany(targetEntity="RemovalsUK\RemovalsBundle\Entity\Post",
     *     mappedBy="author")
     */
    protected $posts;

    public function __construct()
    {
        parent::__construct();
        // your own logic
        $this->posts = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Add post
     *
     * @param \RemovalsUK\RemovalsBundle\Entity\Post $post
     *
     * @return User
     */
    public function addPost(\RemovalsUK\RemovalsBundle\Entity\Post $post)
    {
        $this->posts[] = $post;

        return $this;
    }

    /**
     * Remove post
     *
     * @param \RemovalsUK\RemovalsBundle\Entity\Post $post
     */
    public function removePost(\RemovalsUK\RemovalsBundle\Entity\Post $post)
    {
        $this->posts->removeElement($post);
    }

    /**
     * Get posts
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getPosts()
    {
        return $this->posts;
    }
}
<?php
/**
 * Created by PhpStorm.
 * User: Ezequias
 * Date: 25/06/2016
 * Time: 19:09
 */

namespace RemovalsUK\UserBundle\Entity;


use FOS\UserBundle\Model\Group as BaseGroup;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_group")
 */
class Group extends BaseGroup
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

}
观察结果 登录工作正常,我只想允许用户在注册自己时选择,例如:角色:投标人或角色:司机。如果有人能帮我处理这件事,我将不胜感激。
提前感谢

您需要覆盖记录的默认登记表。

是“投标人”和“司机”两个不同的集团实体吗?嗨,阿尔文,不,他们在同一个集团实体上
# To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
            ROLE_ADMIN:       ROLE_USER
            ROLE_SUPER_ADMIN: ROLE_ADMIN

    # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
    providers:
        fos_userbundle:
                    id: fos_user.user_provider.username
        in_memory:
            memory: ~

    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        login:
                    pattern:  ^/demo/secured/login$
                    security: false
        main:
            pattern: ^/
            form_login:
                     provider: fos_userbundle
                     csrf_token_generator: security.csrf.token_manager
            logout:    true
            anonymous: true

    access_control:
            - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/admin/, role: ROLE_ADMIN }
            - { path: ^/create, role: ROLE_USER }
            - { path: ^/EDIT, role: ROLE_USER }
            - { path: ^/delete, role: ROLE_USER }
            # activate different ways to authenticate

            # http_basic: ~
            # http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate

            # form_login: ~
            #http://symfony.com/doc/current/cookbook/security/form_login_setup.html