RoleInterface 现在已被弃用,将在 4.0 中删除,因此您可以像 Genoud Magloire 所说的那样做,但一定要扩展 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 );
}