模型中的 Zend ACL 与 Zend Navigation
我喜欢将 ACL 绑定到模型的想法,如下所述:
但是如何将其与 Zend Navigation 结合起来?渲染站点地图时,我必须实例化所有模型。
是否有人实际上在至少中等规模的站点上使用过这种方法,并且可以分享他解决性能问题的经验?
I like the idea of binding ACL to models like described here:
But how can I combine this with Zend Navigation? When rendering the sitemap, I'd have to instantiate all the models.
Did someone actually used this approach on at least medium scale site and can share his experience on solving performance issues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 acl 实例直接传递给导航
这是我在 boostrap initAutoload 方法中初始化 acl 的方式
我使用导航 xml 代码来定义我的导航,例如
这定义了列表操作的链接。它可以被所有用户访问,所以
这是来自我的库 acl 文件,该文件派生自 Zend_Acl。有关更多详细信息,请观看此视频教程Zend Framework 1.8 教程 8 zend_navigation 和 zend_acl
You can pass an acl instance straight to the navigation
This is how I init the acl in my boostrap initAutoload method
I use navigation xml code to define my navigation, e.g.
This defines the link for the list action. It can be accessed by all users, so
This is from my library acl file that is derived from Zend_Acl. For more detailed information go through this video tutorial Zend Framework 1.8 tutorial 8 zend_navigation and zend_acl
我知道您不久前问过这个问题,但我认为分享我的代码会很有趣,因为我也遇到了同样的问题。
基本上,我想出的是一种新的 Xml 文件解析方法,这样我就可以直接将我的模型实例化到我的导航 Xml 配置文件中,以便将我的权限正确添加到我的 ACL 树中。
首先让我们看一下我的 Xml 菜单:
这里有趣的是 resource 属性,它们实际上都是代表我的模型的类。
现在,您可能在 Zend 文档中注意到:
这意味着我的模型将被铸成字符串......真糟糕!为了防止这种行为,我使用了这个将资源字符串转换为对象的函数:
该函数允许我递归地将所有值转换为对象,因此在模型中同时设置权限(允许、拒绝... - <代码>setAcl())。
最后,我分三个步骤实例化我的导航:
在您的引导程序中:
希望它能有所帮助;)
I know you asked this question a while ago, but I thought it would be interesting to share my code since I've faced the same problem.
Basically, what I came up with, is a new parsing method for Xml file, so I can directly instantiate my models into my navigation Xml configuration file, so that my privileges are correctly added to my ACL tree.
Let's take a look at my Xml menu first:
What is interesting here is the resource attributes, all of them are actually classes that represent my models.
Now, you probably noticed in the Zend documentation:
which means that my models will be casted into string... bummer! To prevent this behavior, I used this function that transform resources string into objects:
This function allow me to recursively converts all my values into object, and therefore set the privileges at the same time (allow, deny... in your models -
setAcl()
).Finally, I instantiate my navigation in three steps:
In your bootstrap:
Hope it can help ;)