Zend's Acl allows the resource to be created in controller only
But, the controllers might be on any module not just only the default module. So, I read some article off the internet, I found one and tried this:
$acl -> addResource(new Zend_Acl_Resource("admin"));
$acl -> addResource(new Zend_Acl_Resource("admin:page"), "admin");
$acl -> addResource(new Zend_Acl_Resource("admin:posts"), "admin");
But, still, when i browse to 开发者_如何学编程the respective pages, I get errors regarding resouce page
not found, or posts
not found.
How to setup Module Specific ACL Resource?
Update:
$acl -> addrole(new Zend_Acl_Role('guest'))
-> addrole(new Zend_Acl_ROle('admin'), 'admin');
$acl -> addResource(new Zend_Acl_Resource("page")); //controller with same name in admin module exists
$acl -> addResource(new Zend_Acl_Resource("admin"));
$acl -> addResource(new Zend_Acl_Resource("admin:page"), "admin");
$acl -> addResource(new Zend_Acl_Resource("admin:posts"), "admin");
$acl -> deny(null, null);
$acl -> allow('user', 'page', 'view');
$acl -> allow('admin', null);
I'm guessing the code you posted was some sort of pseudo code, as it wasn't valid. Still, this answer should work perfectly fine as is.
$acl->addrole(new Zend_Acl_Role('guest'))
->addrole(new Zend_Acl_Role('admin'), 'guest');
$acl->addResource(new Zend_Acl_Resource("page"));
$acl->addResource(new Zend_Acl_Resource("admin"));
$acl->addResource(new Zend_Acl_Resource("admin:page"), "admin");
$acl->addResource(new Zend_Acl_Resource("admin:posts"), "admin");
$acl->deny();
$acl->allow('guest', 'page', 'view');
$acl->allow('admin');
// Lets run some quick tests...
var_dump($acl->isAllowed('guest', 'page', 'view')); // true
var_dump($acl->isAllowed('guest', 'page', 'edit')); // false
var_dump($acl->isAllowed('guest', 'admin:page', 'view')); // false
var_dump($acl->isAllowed('admin', 'page', 'view')); // true
var_dump($acl->isAllowed('admin', 'page', 'edit')); // false
var_dump($acl->isAllowed('admin', 'admin:page', 'view')); // true
精彩评论