RoleInterface現在已經過時,是由於用於去除4.0,所以你可以做同樣的Genoud馬格洛伊爾說,但一定要延長Symfony\Component\Security\Core\Role\Role
這裏是我的角色實體的例子。
<?php
namespace ExampleCoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Validator\Constraints as Assert;
/**
* ExampleRole
*
* @ORM\Table(name="EXAMPLE_ROLE")
* @ORM\Entity
*/
class ExampleRole extends Role
{
/**
* @var integer
*
* @ORM\Column(name="ID", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
*/
private $id;
/**
* @var string
*
* @Assert\NotBlank()
* @Assert\Length(
* min = 9,
* max = 100,
* minMessage = "Role name must be at least {{ limit }} characters long",
* maxMessage = "Role name cannot be longer than {{ limit }} characters"
*)
* @ORM\Column(name="ROLE_NAME", type="string", length=255, nullable=false, unique=true)
*
*/
private $roleName;
/**
* @var string
*
* @Assert\NotBlank()
* @Assert\Choice({"Y","N"})
*
* @ORM\Column(name="GRANTABLE", type="string", length=1, nullable=false)
*/
private $grantable;
/**
* @var \DateTime
*
* @ORM\Column(name="CREATED_ON", type="datetime", nullable=false)
*/
private $createdOn;
//...and so on with whatever else you want to save.
public function __construct($roleName = null)
{
parent::__construct($roleName);
}
默認情況下,角色作爲列存儲在用戶表中。它實際上是一個序列化數組,因此一個用途可以有多個角色。如果您覺得需要,您當然可以製作自己的實現並擁有用戶角色表。 – Cerad
[此鏈接](http://stackoverflow.com/questions/39198846/symfony3-how-to-store-user-roles-in-database)也可以幫助你 – mapmalith