我的应用程序具有以下结构:
myapp
- applcation
- modules
- default
- controllers
- models
- Acl.php
- views
- Bootstrap.php
- admin
- controllers
- models
- ResourceMapper.php
- RoleMapper.php
- views
- Bootstrap.php
- helpers
- layout
- library
- index.php
我想在Acl.php的admin-module中的Models文件夹中调用类(在默认模块中)。这是我的代码:
class Model_Acl extends Zend_Acl
{
public $_roleModelMapper;
public $_resourceModelMapper;
function init(){
$this->_roleModelMapper = new Admin_Model_RoleMapper();
$this->_resourceModelMapper = new Admin_Model_ResourceMapper();
}
public function initRole(){
$roles = $this->_roleModelMapper->fetchAll();
foreach ($roles as $role){
$this->addRole($role->getRole());
}
}
public function initResource(){
$resources = $this->_resourceModelMapper->fetchAll();
foreach ($resources as $resource){
if ($resource->getParent()==''){
$this->add(new Zend_Acl_Resource($resource->getResource()));
}else{
$this->add(new Zend_Acl_Resource($resource->getResource()),$resource->getParent());
}
}
}
public function __construct()
{
self::init();
//init role
self::initRole();
//init resource
self::initResource();
//other code here
}
}
但我有这样的错误:
Fatal error: Class 'Admin_Model_RoleMapper' not found in C:\xampp\htdocs\test2\application\modules\default\models\Acl.php on line ...
这是我的应用程序\ Bootstrap.php:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
private $_acl = null;
private $_auth = null;
public function _initAutoload()
{
$modelLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH . "/modules/default",
));
//$this->_acl = new Model_Acl();
$this->_acl = new Model_Acl();
$this->_auth = Zend_Auth::getInstance();
if($this->_auth->hasIdentity()){
Zend_Registry::set('role',$this->_auth->getStorage()->read()->role);
}else{
Zend_Registry::set('role','GUEST');
}
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin(new Plugin_AccessCheck($this->_acl));
return $modelLoader;
}
}
?>
我的application.ini确实有:
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ""
我的代码出了什么问题?请帮我。 问候。
答案 0 :(得分:2)
查看管理模块引导类的外观(application / modules / admin / Bootstrap.php)可能很有用。
是否扩展了Zend_Application_Module_Bootstrap或Zend_Application_Bootstrap_Bootstrap?
它应该扩展Zend_Application_Module_Bootstrap,否则模块资源加载器不会使用正确的命名空间进行初始化。
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {
}