【发布时间】:2011-01-31 11:40:33
【问题描述】:
我在使用 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
);
}
这似乎运作良好,我可以毫无问题地使用 View Helpers 中 Zend_Auth 存储中存储的对象。我似乎遇到的问题是,当我尝试在我的 Acl 中使用它时,下面是我的 Acl 中的一个 sn-p,一旦它到达 if($auth->hasIdentity()) { 行,我就会得到进一步详细说明的异常。
$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
谢谢,
马丁
【问题讨论】:
-
你引导你的模块了吗?
-
嗨,Ashley,你是什么意思引导,在我的配置中,我有以下几行,我还需要什么... Autoloadernamespaces[] = "Menu_", resources.modules[] = ""
标签: zend-framework zend-auth zend-session