Hello, In AuthController.php you setup an ACL object, which goes out of scope at the end of the script and is destroyed at that time.
In FooController.php you are creating a new and separate ACL object. Of course it does not have the information that the ACL object created in AuthController.php had - it's a different object! :) If you need the ACL object (or any other data stored in a user variable, for that matter) available across all your controllers, you must persist the data somewhere (e.g., the PHP session, a database). But this is probably not the best approach. I understand that people have had a lot of success with implementing a front controller plugin that implements authorization with preDispatch(). For more information about creating a front controller plugin, please see: http://framework.zend.com/manual/en/zend.controller.plugins.html Hope this helps! Best regards, Darby wenbert wrote: > i have this in one of the controllers in my AuthController.php > > // set access controlls > // ------------------------------------- > $acl = new Zend_Acl(); > > //define resources > $acl->add(new Zend_Acl_Resource('admin_pages')); > $acl->add(new Zend_Acl_Resource('claim')); > $acl->add(new Zend_Acl_Resource('views')); > $acl->add(new Zend_Acl_Resource('reports')); > $acl->add(new Zend_Acl_Resource('research')); > > $roles = explode(' ',$data['group_names']); > foreach ($roles as $role) { > $myrole = new Zend_Acl_Role($role); > $acl->addRole($myrole); > > if ($role == 'admin') { > $acl->allow($myrole, 'admin_pages', array('admin_access')); > } elseif ($role == 'xxx') { > $acl->allow($myrole, array('claim', 'views', 'reports'), > array('create_claim', 'save_claim', 'close_claim', 'view')); > } elseif ($role == 'yyy') { > $acl->allow($myrole, array('research', 'views', 'reports'), > array('research_open', 'view')); > } > //echo $acl->isAllowed($role, null, 'research_open') ? "$role: > allowed<br />" : "$role: denied<br />"; > } > // ------------------------------------- > > BUT, i can't access the ACL in another FooController.php > Zend_Loader::loadClass('Zend_Acl'); > Zend_Loader::loadClass('Zend_Acl_Role'); > Zend_Loader::loadClass('Zend_Acl_Resource'); > $acl = new Zend_Acl; > $acl->isAllowed('xxx', 'claim', 'create_claim') ? "myrole: allowed<br />" : > "myrole: denied<br />"; > > i get an error that says: > Fatal error: Uncaught exception 'Zend_Acl_Role_Registry_Exception' with > message 'Role 'xxx' not found' > > how would i access the stuff i created in my AuthController.php from in > other controllers/actions? > so that I can do this: > $acl->isAllowed('xxx', 'claim', 'create_claim') ? "myrole: allowed<br />" : > "myrole: denied<br />"; > in any part of my application? > > any reply will be appreciated :) > thanks
