Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-27-2008, 02:34 AM
Junior Member
 
Join Date: Feb 2008
Posts: 3
Default can i define different zend_acl resource in a php file?

in a file, i want to define different resources for diffrent roles , can i use zend_acl?
does zend_acl can only be used in the directories or different files?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 03:43 AM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

you can access different ACLs at differant parts of your site; just have them pointing to different configuration files.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 04:55 AM
Junior Member
 
Join Date: Feb 2008
Posts: 3
Default

but i want to point diffrent sources to diffrent codes in a file, not several files. can i?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 05:34 AM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

I am not sure what you mean. A Resource is an object to which access is controlled. A Role is an object that may request access to a Resource. You can have as many roles and resources as you like on one ACL. You don't need to make seperate lists.

If you save the ACL as a variable in Zend_Registry, it can be accessed ANYWHERE on your site. This is from my bootstrap file:

Code:
// setup Access Control List
$acl = new Zend_Acl();

$roleGuest = new Zend_Acl_Role('guest');
$acl->addRole($roleGuest);
$acl->addRole(new Zend_Acl_Role('staff'), $roleGuest);
$acl->addRole(new Zend_Acl_Role('editor'), 'staff');
$acl->addRole(new Zend_Acl_Role('administrator'));

$acl->allow('guest', null, 'view');
$acl->allow('staff', null, array('edit', 'submit', 'revise'));
$acl->allow('editor', null, array('publish', 'archive', 'delete'));
$acl->allow('administrator');

Zend_Registry::set('acl', $acl);

To get this variable from the registry:
Code:
$registry = Zend_Registry::getInstance();
$this->acl = $registry['acl'];

Last edited by notrub225 : 02-27-2008 at 05:37 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 05:54 AM
Junior Member
 
Join Date: Feb 2008
Posts: 3
Default

for example
in a php file
Code:
echo (part A-only be viewed by role A);//i want to define this part as resource A
echo (part B-only be viewed by role B);//i want to define this part as resource B
can i?

and how i do this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 07:35 PM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

Quote:
Originally Posted by rockdeaf View Post
for example
in a php file
Code:
echo (part A-only be viewed by role A);//i want to define this part as resource A
echo (part B-only be viewed by role B);//i want to define this part as resource B
can i?

and how i do this?
Once you have created the access control list, you use the isAllowed() method of Zend_Acl to check if a resource is allowed given the role specified. This function will return a boolean true or false:

Code:
if($acl->isAllowed('roleA', null, 'resourceA')) {
    echo $outputAllowedForRoleA;
}

if($acl->isAllowed('roleB', null, 'resourceB')) {
    echo $outputAllowedForRoleB;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:53 PM.