Zend_Auth / Zend_Session error and storing objects in Auth Storage
Posted
by
Martin
on Stack Overflow
See other posts from Stack Overflow
or by Martin
Published on 2011-01-31T11:40:33Z
Indexed on
2011/01/31
23:25 UTC
Read the original article
Hit count: 333
Hi All,
I have been having a bit of a problem with Zend_Auth and keep getting an error within my Acl.
Within my Login Controller I setup my Zend_Auth storage as follows
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
if ($result->isValid()) {
$userId = $adapter->getResultRowObject(array('user_id'), null)->user_id;
$user = new User_Model_User;
$users = new User_Model_UserMapper;
$users->find($userId, $user);
$auth->getStorage()->write(
$user
);
}
This seems to work well and I am able to use the object stored in the Zend_Auth storage within View Helpers without any problems. The problem that I seem to be having is when I try to use this within my Acl, below is a snippet from my Acl, as soon as it gets to the if($auth->hasIdentity()) {
line I get the exception detailed further down.
The $user->getUserLevel()
is a methord within the User Model that allows me to convert the user_level_id that is stored in the database to a meaning full name. I am assuming that the auto loader sees these kind of methords and tries to load all the classes that would be required.
When looking at the exception it appears to be struggling to find the class as it is stored in a module, I have the Auto Loader Name Space setup in my application.ini.
Could anyone help with resolving this?
class App_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
protected $_roleName;
public function __construct()
{
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity()) {
$user = $auth->getIdentity();
$this->_roleName = strtolower($user->getUserLevel());
} else {
$this->_roleName = 'guest';
}
}
}
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Zend_Session::start() -
\Web\library\Zend\Loader.php(Line:146): Error #2 include_once() [<a href='function.include'>function.include</a>]:
Failed opening 'Menu\Model\UserLevel.php' for inclusion
(include_path='\Web\application/../library;\Web\library;.;C:\php5\pear') Array' in \Web\library\Zend\Session.php:493
Stack trace:
#0 \Web\library\Zend\Session\Namespace.php(143): Zend_Session::start(true)
#1 \Web\library\Zend\Auth\Storage\Session.php(87): Zend_Session_Namespace->__construct('Zend_Auth')
#2 \Web\library\Zend\Auth.php(91): Zend_Auth_Storage_Session->__construct()
#3 \Web\library\Zend\A in \Web\library\Zend\Session.php on line 493
Thanks,
Martin
© Stack Overflow or respective owner