Sonata管理员捆绑包列表用户



我有Sonata Admin Bundle和Sonata用户捆绑包(带有用户和组的FosuserBundle(。

在UserAdmin.php中,我需要修改列表查询以仅显示特定组的用户。

我尝试了

public function createQuery($context = 'list')
    {
        $query = parent::createQuery($context);
        $query->andWhere(
            $query->expr()->eq($query->getRootAliases()[0] . '.groups', ':my_param')
        );
        $query->setParameter('my_param', '9'); //9 is the id of a group
        return $query;
    }

但是我有

[Semantical Error] line 0, col 72 near 'groups = :my': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected.

我找到了解决方案,正确查询是:

public function createQuery($context = 'list')
    {
        $query = parent::createQuery($context);
        $query->andWhere(
            $query->expr()->isMemberOf(':groupId', $query->getRootAliases()[0] . '.groups')
        );
        $query->setParameter('groupId', '9'); //9 is the id of a group

        return $query;
    }

最新更新