Zend_Auth / Zend_Session 错误以及在 Auth Storage 中存储对象
我在使用 Zend_Auth 时遇到了一些问题,并且在我的 Acl 中不断出现错误。
在我的登录控制器中,我按如下方式设置 Zend_Auth 存储
$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
);
}
这似乎运行良好,我能够在视图助手中使用存储在 Zend_Auth 存储中的对象,没有任何问题。我似乎遇到的问题是,当我尝试在我的 Acl 中使用它时,下面是我的 Acl 的一个片段,一旦它到达 if($auth->hasIdentity()) {< /code> 行我进一步详细了解了异常。
$user->getUserLevel() 是用户模型中的一种方法,它允许我将存储在数据库中的 user_level_id 转换为有意义的全名。我假设自动加载器看到这些方法并尝试加载所需的所有类。
当查看异常时,它似乎很难找到该类,因为它存储在模块中,我在 application.ini 中设置了自动加载器名称空间。
有人可以帮忙解决这个问题吗?
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
谢谢,
马丁
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该问题与取消序列化对象有关。例外是告诉你出了什么问题。 Zend_Loader 找不到您的
UserLevel
类(我假设这是User_Model_User
的成员)。在构建 ACL 时,您的包含路径设置是否正确?
一个巧妙的解决方法是将其添加
到您的 ACL 类文件中。
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 ofUser_Model_User
).Is your include path set correctly at the time when your ACL is constructed?
A hacky work-around would be to add
to your ACL class file.