Role Interface and Manage Roles

大憨熊 提交于 2019-12-04 19:09:39

You have two getRoles functions:

  • One is the function for the UserInterface interface which returns a list of Roles
  • The other is the getter for your $roles property

Since both functions cannot be called the same and they cannot be the same function because they need to return different types, and since the first function needs to follow the interface I suggest you change the name of the second function. Since this needs to reflect the name of the property, you should change this name.

So, you need to do something like:

/**
 * @ORM\ManyToMany(targetEntity="Role", inversedBy="users", cascade={"persist"})
 */
protected $userRoles;

/* interface */

function getRoles()
{
    return $this->userRoles->toArray();
}

/*getter*/

function getUserRoles() {
    return $this->userRoles;
}

and then

public function buildForm(FormBuilder $builder, array $options)
{
    $builder->add('userRoles');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!