Reputation: 6421
I've been reading up on the Zend_Acl component of the Zend framework. I would like to implement a database driven solution but have noticed that it looks like I have go load ALL roles, permissions, and resources from the database to build an ACL. It doesn't look like it's easy or possible to lazy load these rules into the ACL as needed. It looks like if any lazy loading is implemented, the entire Zend_Acl class has to be gutted. Does anyone have a good exampke of how this can be accomplished?
Upvotes: 2
Views: 384
Reputation: 196
The approach I would recommend is to build the ACL from the DB and cache it with Zend_Cache so it doesn't need to be loaded with every request.
Firstly, build the ACL object with $acl = new Zend_Acl();
Then get your roles, resources and permissions from the DB. Loop through your resources and roles and add them with $acl->addResource()
and $acl->addRole()
, then add permissions with $acl->allow()
Assuming you have bootstrapped your $cache
object and it is available here (via Zend_Registry or whatever), do something like:
if (($acl = $cache->load('acl')) === false) {
$acl = $this->_buildACL(); // Build you ACL in the _buildAcl() method
$cache->save($acl, 'acl', array('ACL'));
}
Zend_Registry::set('acl', $acl);
Upvotes: 1