« Return to Thread: Zend_Acl / Zend_Auth example scenario

Re: Zend_Acl / Zend_Auth example scenario

by Jim Scherer :: Rate this Message:

Reply to Author | View in Thread

Simon,

Great example but I have two questions. I'm getting a 'Fatal error: Can not call constructor' any thoughts? What is the point of $roleGuest? I'm able to just do this

         $this->addRole(new Zend_Acl_Role('guest'));
         $this->addRole(new Zend_Acl_Role('member'), 'guest');
         $this->addRole(new Zend_Acl_Role('admin'), 'member');

and everything seems fine. Why do you break out $roleGuest?

The framework is very valuable to me. It is helping me to organize and simplify my code while reducing the amount of code I am writing. The examples are educating about how to best utilize the framework and php in general. Keep up the good work and please continue post usage examples.

Thanks, Jim

Simon Mundy wrote:
To satisfy the needs of the Access rules, we create a subclassed  
instance of Zend_Acl like so:-

class MyAcl extends Zend_Acl
{
     public function __construct(Zend_Auth $auth)
     {
         parent::__construct();

         $roleGuest = new Zend_Acl_Role('guest');

        $this->add(new Zend_Acl_Resource('home'));
        $this->add(new Zend_Acl_Resource('news'));
        $this->add(new Zend_Acl_Resource('tutorials'));
        $this->add(new Zend_Acl_Resource('forum'));
        $this->add(new Zend_Acl_Resource('support'));
        $this->add(new Zend_Acl_Resource('admin'));

         $this->addRole($roleGuest);
         $this->addRole(new Zend_Acl_Role('member'), 'guest');
         $this->addRole(new Zend_Acl_Role('admin'), 'member');

         // Guest may only view content
         $this->allow('guest', 'home');
         $this->allow('guest', 'news');
         $this->allow('guest', 'tutorials');
         $this->allow('member', 'forum');
         $this->deny('member', 'forum', 'update'); // Remove specific  
privilege
         $this->allow('member', 'support');
         $this->allow('admin'); // unrestricted access

         // Add authoring ACL check
         $this->allow('member', 'forum', 'update', new  
MyAcl_Forum_Assertion($auth));
         // NOTE: Dependency on auth object to allow getIdentity()  
for authenticated user object
     }
}

 « Return to Thread: Zend_Acl / Zend_Auth example scenario