Prev | Current Page 190 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"


Zend_Acl_Resource
A resource is something that you want to protect. A typical resource in a Zend Framework application would
be a controller or action. For example you may want to protect access to the forums module controller so that
only those users belonging to the member role have access to the controllers within it. Zend_Acl_Resource is
as simple as Zend_Acl_Role and just holds the name of the resource, so creating one is simply a case of:
$forumResource = new Zend_Acl_Resource('comments');
A resource is attached to Zend_Acl in a similar manner to a role using the addResource() member function
and again, parents are supported:
$acl = new Zend_Acl();
$acl->addRole(new Zend_Acl_Role('member'));
$acl->addRole(new Zend_Acl_Role('moderator'), 'member');
$acl->addResource(new Zend_Acl_Resource('forum'));
$acl->addResource(new Zend_Acl_Resource('posts'), 'forum');
$acl->addResource(new Zend_Acl_Resource('threads'), 'forum');
In this example, we have created resource called posts and threads that are children of the forum resource.
If we are mapping resources to modules and controllers, then the ???posts??? and ???threads??? resources represent
controllers within the forum module.
Setting up Zend_Acl??™s Permissions
The final part of the setting up a Zend_Acl object for use is telling the object which permissions a given
role has for accessing a given resources.


Pages:
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
Adamski ubrania parasole reklamowe A*Teens rolety rzymskie