0
我的應用程序的結構爲:不能從默認模塊中調用另一個模塊中的模型類?
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(默認模塊)。在這裏我的代碼:
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 = ""
那麼我的代碼有什麼問題?請幫幫我。 此致敬禮。
我在每個模塊中都有一個Bootstrap文件,就像上面的代碼一樣。我只是找到一種方法來解決問題,在Acl.php文件中創建一個新的連接。還有別的辦法嗎? – 2011-06-07 01:42:52
還有一件事,我將我的項目從Windows 7複製到Ubuntu中的/ home/myName/public_html文件夾(鏈接到/ opt/lammp/htdocs)。但我得到了這個錯誤:警告:未知:未能打開流:權限被拒絕在未知的第0行。因爲我知道這可能是權限問題,但我該如何解決? – 2011-06-07 01:46:44