Sonata Admin Bundle 过滤器显示来自角色用户的实体 [英] Sonata Admin Bundle filter show entity from role user

查看:40
本文介绍了Sonata Admin Bundle 过滤器显示来自角色用户的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SonataAdminBundle 开发一个仪表板,它根据用户的角色显示一些实体.

I'm trying to develop a dashboard with the SonataAdminBundle, which displays some entities depending on the role of the user.

例如,如果连接的用户具有 ROLE_SUPER_ADMIN,则应显示所有实体.但如果用户是 ROLE_USER,则只应显示一个确定的实体,不是所有实体.

For instance, if the connected user has the ROLE_SUPER_ADMIN, all entities should be shown. But if the user is ROLE_USER, only a determinated entity should be shown, not all of them.

是否可以在实体的服务声明中进行?

Is it possible do it in the service declaration of the entity?

推荐答案

为了将来参考,诀窍是在 Sonata 中使用 createQuery 和 PermanentParamters 来强制过滤器.我刚刚写了一篇关于这个的文章:http://www.theodo.fr/blog/2016/09/sonata-for-symfony-hide-your-filters/

for future reference the trick is to use createQuery and permanentParamters in Sonata to be able to enforce filters. I have just written an article about that: http://www.theodo.fr/blog/2016/09/sonata-for-symfony-hide-your-filters/

这篇关于Sonata Admin Bundle 过滤器显示来自角色用户的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆