Sonata Admin Bundle 列出一个组的用户
Sonata Admin Bundle list users of a group
我有 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.
我找到了解决方案,正确的查询是:
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;
}
我有 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.
我找到了解决方案,正确的查询是:
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;
}