Zend:通过继承而不是组合进行 ACL 和 Auth

发布于 2024-12-05 21:00:15 字数 420 浏览 0 评论 0原文

我读过几本不同的 Zend 书籍,其中 ACL 和 Auth 是使用组合实现的。它们通常涉及带有 preDispatch 方法的 Action Helpers,在引导程序中注册。

现在,在迄今为止的所有编码中,我的每个控制器都执行相同的 ACL 和 Auth 方法。因此我想我不妨使用继承来实现这一点。我错过了什么吗?继承似乎更简单一些。

早些时候,我使用 Action Helpers 来避免将所有规则加载到 ACL 对象中。 (我只是将当前控制器注册为 ACL 资源,并为其添加规则)。

然而,当我开始集成 Zend Navigation 时,我发现我需要所有 ACL 规则(无论控制器如何),以便确定向用户呈现哪些菜单选项。

我想通过组合,我的 ACL 和 Auth 帮助程序在其他项目上更容易使用,但这对我来说只是一个小小的好处。

谢谢!

I have read a few different Zend books where ACL and Auth are implemented using composition. They generally involve Action Helpers with preDispatch methods, registered in the bootstrap.

Now, in all of the coding so far, the same ACL and Auth methods are executed for each of my controllers. Therefore I am thinking that I might just as well use inheritance to accomplish this. Am I missing something? Inheritance just seems a bit more straightforward.

Earlier on I was using Action Helpers to avoid having to load all the rules into the ACL object. (I was just registering the current controller as the ACL resource, and adding the rules for that).

When I came to integrate Zend Navigation, however, I found that I needed all the ACL rules (irrespective of controller), in order to work out which menu options to present to the user.

I guess that with composition, my ACL and Auth helpers are easier to use on other projects, but that's only a small benefit in my case.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸里的那抹悲凉 2024-12-12 21:00:15

您也可以使用控制器插件,请参阅以前的答案,看起来像一个组合,但非常接近控制器的继承。这并不妨碍您拥有可用于菜单的 Zend_Acl 对象。

You could use controllers plugins as well, see previous answer, seems like a composition but is very near inheritance of controllers. And that does not prevent you from having a Zend_Acl object available for menus.

燕归巢 2024-12-12 21:00:15

一般来说,有很多充分的理由选择组合而不是继承。您可以在这里看到很多意见:更喜欢组合而不是继承?

也就是说,这取决于您可以决定是否有更好的理由使用继承而不是组合。您可以将 ACL 集成到基本控制器类中,并使所有控制器都继承它。您在这里还有另一个问题: Zend 中所有控制器的基本控制器框架

希望有帮助,

There are many valid reasons to prefer composition over inheritance, in general. You can see a lot of opinions here: Prefer composition over inheritance?

That said, it's up to you to decide if you have better reasons to use inheritance instead of composition. You can integrate your ACL in a base controller class and make all your controllers inherit from it. You have another SO question about it here: Base controller for all controllers in zend framework

Hope that helps,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文