2016-06-28 1 views
0

그룹 및 역할을 사용하여 FOSUserBundle을 사용하여 로깅 시스템을 구현하고 있습니다. 새 사용자가 적용 할 역할을 선택할 수있는 FOSUserBundle의 사용자 등록 양식에서 역할 이름 (역할 : 입찰자 및 역할 : 드라이버)의 드롭 다운 목록을 표시하고 싶습니다. 어떻게하면됩니까?Symfony 3를 사용하여 FOSUserBundle 등록 양식의 드롭 다운 역할 표시

<?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; 

} 

Security.yml

# 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 
,369

<?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; 
    } 
} 

그룹 엔티티

사용자 엔티티 : 다음은 내 코드입니다

관측 로그인이 완벽하게 작동합니다. 사용자가 직접 등록 할 때 역할 : 입찰자 또는 역할 : 드라이버을 선택할 수 있습니다. 누군가가이 문제를 도울 수 있다면 고맙겠습니다. 미리 감사드립니다.

+0

"입찰자"와 "드라이버"는 서로 다른 두 개의 그룹 구성 요소입니까? –

+0

안녕하세요 앨빈, 아니요. 그들은 같은 단체 그룹에 있습니다. – prezequias

답변

-1

here과 같이 기본 등록 양식을 덮어 써야합니다.