Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我需要申报吗;角色“;在symfony2中类作为数组还是arrayCollection?_Php_Symfony_Doctrine Orm - Fatal编程技术网

Php 我需要申报吗;角色“;在symfony2中类作为数组还是arrayCollection?

Php 我需要申报吗;角色“;在symfony2中类作为数组还是arrayCollection?,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我有这样一个场景: 用户将属于组 组将具有特定的角色 现在我想知道我需要在Group.php中声明这个吗 这是,这是 或 我不知道这是如何与symfony安全工作。我的意思是symfony security希望在arraycollection或arraycollection中扮演什么样的角色。那么,您的问题是arraycollection或arraycollection 使用ArrayCollection,因为它在ORM上下文中做得更好,并且更易于扩展/操作(请参阅:) 有关在条令中设置集合

我有这样一个场景:

  • 用户
    将属于
  • 将具有特定的
    角色
现在我想知道我需要在Group.php中声明这个吗

这是,这是


我不知道这是如何与symfony安全工作。我的意思是symfony security希望在arraycollection或arraycollection中扮演什么样的角色。

那么,您的问题是
arraycollection
arraycollection

使用ArrayCollection,因为它在ORM上下文中做得更好,并且更易于扩展/操作(请参阅:)

有关在条令中设置集合的更多信息,请参阅 在文档中


FOSUserBundle

<>你也可以考虑使用优秀的。它完全支持
角色

访问控制列表(ACL)

您可能还想签出ACL:

在复杂的应用程序中,您经常会遇到这样的问题:访问决策不仅基于请求访问的人员(令牌),而且还涉及请求访问的域对象。这就是ACL系统的用武之地


那么,您的问题是
Array
还是
ArrayCollection

使用ArrayCollection,因为它在ORM上下文中做得更好,并且更易于扩展/操作(请参阅:)

有关在条令中设置集合的更多信息,请参阅 在文档中


FOSUserBundle

<>你也可以考虑使用优秀的。它完全支持
角色

访问控制列表(ACL)

您可能还想签出ACL:

在复杂的应用程序中,您经常会遇到这样的问题:访问决策不仅基于请求访问的人员(令牌),而且还涉及请求访问的域对象。这就是ACL系统的用武之地


Symfony 2期望和
Role
array
作为
getRoles()
方法中的返回值。由于
用户
可以有多个
,而每个组可能有多个
角色
,因此我会:

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User
{
    /* @ORM\ManyToMany(targetEntity="Group", inversedBy="users") */
    private $groups;

    public function __construct()
    {
        $this->groups = new \Doctrine\Common\Collections\ArrayCollection();
    }

    public function getRoles()
    {
        $roles = array();

        foreach($this->groups as $group) :
            $roles = array_merge($roles, $group->getRoles()->toArray());
        endforeach;

        return $roles;
    }
}

Symfony 2期望和
角色的
数组
作为
getRoles()
方法中的返回值。由于
用户
可以有多个
,而每个组可能有多个
角色
,因此我会:

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User
{
    /* @ORM\ManyToMany(targetEntity="Group", inversedBy="users") */
    private $groups;

    public function __construct()
    {
        $this->groups = new \Doctrine\Common\Collections\ArrayCollection();
    }

    public function getRoles()
    {
        $roles = array();

        foreach($this->groups as $group) :
            $roles = array_merge($roles, $group->getRoles()->toArray());
        endforeach;

        return $roles;
    }
}
/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User
{
    /* @ORM\ManyToMany(targetEntity="Group", inversedBy="users") */
    private $groups;

    public function __construct()
    {
        $this->groups = new \Doctrine\Common\Collections\ArrayCollection();
    }

    public function getRoles()
    {
        $roles = array();

        foreach($this->groups as $group) :
            $roles = array_merge($roles, $group->getRoles()->toArray());
        endforeach;

        return $roles;
    }
}