Мое приложение имеет структуру:
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
Я хочу вызывать классы в папке Models в admin-модуле из Acl.php (в модуле по умолчанию). Вот мой код:
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 = ""
Так что не так с моим кодом? Пожалуйста, помогите мне.
Привет.