2011-06-06 100 views
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 = "" 

那么我的代码有什么问题?请帮帮我。 此致敬礼。

回答

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 { 



} 
+0

我在每个模块中都有一个Bootstrap文件,就像上面的代码一样。我只是找到一种方法来解决问题,在Acl.php文件中创建一个新的连接。还有别的办法吗? – 2011-06-07 01:42:52

+0

还有一件事,我将我的项目从Windows 7复制到Ubuntu中的/ home/myName/public_html文件夹(链接到/ opt/lammp/htdocs)。但我得到了这个错误:警告:未知:未能打开流:权限被拒绝在未知的第0行。因为我知道这可能是权限问题,但我该如何解决? – 2011-06-07 01:46:44

相关问题