cakephp ACL:列出用户可以访问的所有文档
我现在使用 cakephp 一段时间了,刚刚开始使用 ACL。我已经启动并运行了,除了一件事。如何找到当前用户可用的所有文档?
我在 Aros 表中设置了几个组(超级用户、管理员和普通用户)。我有几个文档,超级用户和管理员都应该可以访问,但普通用户只能访问特定的文档。我想到的最接近的事情是:
$this->data=$this->Document->find('all',array('fields'=>array('Document.id','Document.filename','Document.title')));
foreach($this->data as $i=>$document){
if($this->Acl->check(array('model'=>'User','foreign_key'=>$this->Session->read('User.id')),array('model'=>'Document','foreign_key'=>$document['Document']['id']))!=1){
unset($this->data[$i]);
}
}
上述“解决方案”的问题是它首先查询所有文档(在不久的将来将变成数千个),然后通过删除所有无法访问的文档将其减少到可能的几个文档$this->data 数组中的文档...
I am using cakephp for some time now and just started with ACL. I've got it up and running, except one thing. How can I find all documents available to the current user?
I have several groups (super users, admins and general users) set up in the Aros table. I have several documents which should be all accessible to the super users and admins, but only specific ones to the general users. The closest thing I came up with is:
$this->data=$this->Document->find('all',array('fields'=>array('Document.id','Document.filename','Document.title')));
foreach($this->data as $i=>$document){
if($this->Acl->check(array('model'=>'User','foreign_key'=>$this->Session->read('User.id')),array('model'=>'Document','foreign_key'=>$document['Document']['id']))!=1){
unset($this->data[$i]);
}
}
The problem with the above "solution" is that it first queries all documents (which will become several thousands in the near future) and then brings it down to potentially a couple of documents by deleting all inaccessible documents from the $this->data array...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在用户模型上创建一个
findAccessibleDocuments
方法来直接查询数据库。您必须弄清楚 ACL 表的结构才能提出查询。抱歉,我无法给您完整的答案,但我现在很着急,您可以继续努力,我稍后会再回复,看看进展如何,也许会对您有更多帮助。
You could create a
findAccessibleDocuments
method on the User Model that queries the database directly. You'll have to figure out the structure of the ACL tables to come up with the query.Sorry I can't give you the complete answer, but I'm in a rush now, you can work on it and I'll get back to this later to see how it went and maybe help you more.