开发者

Couldnt call A Model Class in Another Module From Default Module?

My application has the structure :

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

I wa开发者_JS百科nt to call classes in the Models folder in admin-module from Acl.php (in the default module). Here my code :

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
    }
}

But I had error like this:

Fatal error: Class 'Admin_Model_RoleMapper' not found in C:\xampp\htdocs\test2\application\modules\default\models\Acl.php on line ...

Here my application\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;
    }

 } 
?>

My application.ini does have :

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ""

So what's wrong with my code? Please help me. Regards.


It may be useful to see how your admin module bootstrap class looks like (application/modules/admin/Bootstrap.php).

Is it extending Zend_Application_Module_Bootstrap or Zend_Application_Bootstrap_Bootstrap ?

It should extends Zend_Application_Module_Bootstrap otherwise the module resource loader is not initialized with the proper namespace.

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {



}  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜