Hi All,
I am new to Zend Framework (2nd week of job), I am having an issue with
retrieving the user role from the session:
$this->_aclSession = new Zend_Session_Namespace('acl');//init method
$this->_role = $this->_aclSession->role;//predispatch method
I have also tried the above, both lines in the init and both lines in the
predispatch just as a test with the same result as I'll explain now.
My AuthController is for a CMS, in this auth controller I am trying to both
authenticate with Zend_Auth and the check for access privileges with
Zend_Acl.
I know this to be working in my current environment as I have inherited code
from previous employee. However they have Authentication in Auth controller
in different module and Acesss Controller in Admin Controller in same moudle
as auth controller. In my module I need to do this in one controller, one
action through a login form.
Problem: When I login the first time I get an exception included below. This
states that guest is not recognised, not sure why that is as guest is
defined in the Acls which are quite complex. (Not sure when these Acls are
loaded, maybe registry is not loaded yet, but can't see this being done
explicitly in the AdminController code in existence already in the other
module).
The exception stems from my:
$allowed = $this->_acls->inheritsRole($this->_aclSession->role, new
MycCore_Acl_Role_Entity(MyClub_Acl_Role::SITE_ADMI N));
as you can see. $this->_aclSession->role defaults to 'guest' as it is not
reading the correct role for the authenticated user.
Fatal error: Uncaught exception 'Zend_Acl_Role_Registry_Exception' with
message 'Role 'guest' not found' in
C:\xampp\htdocs\myClub\dev\library\Zend\Acl\Role\R egistry.php:132 Stack
trace: #0 C:\xampp\htdocs\myClub\dev\library\Zend\Acl\Role\R
egistry.php(200): Zend_Acl_Role_Registry->get('guest') #1
C:\xampp\htdocs\myClub\dev\library\Zend\Acl.php(19 3):
Zend_Acl_Role_Registry->inherits('guest', Object(MycCore_Acl_Role_Entity),
false) #2 C:\xampp\htdocs\myClub\dev\application\modules\cms
\controllers\AuthController.php(107): Zend_Acl->inheritsRole('guest',
Object(MycCore_Acl_Role_Entity)) #3
C:\xampp\htdocs\myClub\dev\application\modules\cms
\controllers\AuthController.php(73): Cms_AuthController->_adminPrivileges()
#4 C:\xampp\htdocs\myClub\dev\library\Zend\Controller \Action.php(513):
Cms_AuthController->loginAction() #5
C:\xampp\htdocs\myClub\dev\library\Zend\Controller
\Dispatcher\Standard.php(289):
Zend_Controller_Action->dispatch('loginAction') #6
C:\xampp\htdocs\myClub\dev\library\Zend\Controller \Front.php(946):
Zend_Contro in C:\xampp\htdocs\myClub\dev\library\Zend\Acl\Role\R
egistry.php on line 132
If I press refresh on the page at this stage, the correct role data is then
loaded from the session and I can authenticate as desired for admin
privileges and it all works.
My questions are:
Why is the role data not loaded for the user correctly the first time?
Is this related to why 'guest' role does not yet exist in the Registry
(because it does exist later)?
Are the following code lines I have related to gathering 'CurrentUser's role
data from the session:
$storage = Zend_Auth::getInstance()->getStorage();
$storage->write($this->_user);
Thanks in advance for any help.
Paul.
--
View this message in context:
http://www.nabble.com/ACL-Session-data-unavilable-until-refresh%21-tp25924166p25924166.html
Sent from the Zend Framework mailing list archive at Nabble.com.