Zend_Acl 是否必要?
我有一个基于角色的权限系统,我不确定 Zend_Acl 是否必要,所以我想问我是否正确。
相关网络应用程序没有单独的管理屏幕,任何人都可以访问所有控制器/操作。所以我无法想象在这样的开放系统中我可以称之为“资源”。
但某些用户角色可以看到未按用户 ID 过滤的网格 - 因此超级管理员可以看到所有数据, 和“x admins”查看所有“x”数据。
这种情况下 Zend_acl 系统是否过多?如果没有它,事情就会很简单,我只需在 init() 中获取用户角色并在控制器的某些部分检查它。
I have a role-based permissions system where I am not sure Zend_Acl is necessary, so I'd like to ask if I am right.
The web applications in question doesn't have a separate admin screens, all controllers/actions are accessible to anyone. So I can't imagine what I can call a "resourse" in such open system.
But some user roles can see grids not filtered by user id - so super admins see all data,
and "x admins" see all "x" data.
Is Zend_acl system excessive in this case? Without it things would be simple, I'd just get user role in init() and check against it in some parts of controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅仅因为采埃孚存在某些东西,并不意味着您必须不惜一切代价使用它。您不会因此获得奖励积分。如果您觉得 Zend_Acl 对于您的用例来说太过分了,请使用更简单的方法。这是完全可以接受的。
实际上,在我的一个应用程序中,我使用
ActionHelper
来检查用户的角色。该帮助器有一个方法requireRole()
,它接受字符串形式的所需角色。现在,当我需要限制某个操作时,我只需首先调用此辅助方法即可。如果我需要限制整个控制器,我会将调用放在init()
方法中。缺点是访问控制不集中。在另一个应用程序中,我只有一个需要访问限制的控制器。在该应用程序中,我使用了一个 ControllerPlugin 来检查请求的控制器是否是受限控制器以及用户是否具有所需的角色。这也很好用,我可以根据需要在检查中添加额外的控制器。
所以,使用适合的东西:)
Just because something exists in ZF, doesnt mean you have to use it any cost. You dont get bonus points for it. If you feel Zend_Acl to be overkill for your usecase, use your simpler approach. That's perfectly acceptable.
Actually, in one of my apps, I am using an
ActionHelper
to check on a user's role. The helper has a single methodrequireRole()
that accepts the required role as a string. Now, when I need to restrict an action, I simply call up this helper method as the first thing. If I need an entire controller to be restricted, I place the call in theinit()
method. Drawback is, access control is not centralized.In another app, I only have one single controller that needs access restriction. In that app, I used a
ControllerPlugin
that would check if the requested controller is the restricted controller and if the user has the required role for that. That worked fine as well and I could have added additional controllers to the check as needed.So, use what fits :)