开发者

Zend_Auth / Zend_Session error and storing objects in Auth Storage

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-&g开发者_开发百科t;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


The problem is related to un-serializing an object. The exception is telling you what's wrong. Zend_Loader cannot find your UserLevel class (I'm assuming this is a member of User_Model_User).

Is your include path set correctly at the time when your ACL is constructed?

A hacky work-around would be to add

require_once 'path/to/Menu/Model/UserLevel.php';

to your ACL class file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜