【问题标题】:Sonata Admin Bundle list users of a groupSonata Admin Bundle 列出组的用户
【发布时间】:2019-07-01 12:24:12
【问题描述】:

我有 Sonata Admin Bundle 和 Sonata User Bundle(带有用户和组的 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.

【问题讨论】:

    标签: symfony sonata-admin symfony-sonata sonata-user-bundle


    【解决方案1】:

    我找到了解决办法,正确的查询是:

    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;
        }
    

    【讨论】:

      猜你喜欢
      • 2016-09-03
      • 2018-07-22
      • 2016-04-20
      • 1970-01-01
      • 2013-03-06
      • 2016-10-11
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      相关资源
      最近更新 更多