Zend Framework Modules can't find/load Models

后端 未结 4 1631
北恋
北恋 2021-02-11 05:12

For some frustrating reason, I configured some Modules, which seemed to work fine, However I cannot load a Modules Models. If I move the Models to the Default they load, but I j

相关标签:
4条回答
  • 2021-02-11 05:48

    1-feel free to delete this cuz you don't need it any more :

    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
    

    and place this code inside you Bootstrap.php file [application bootstrap ] not the module bootstrap

    public function _initAutoload()
    {
    $autoloader = new Zend_Application_Module_Autoloader(array(
    'namespace' => '' , 
    'basePath' => dirname(__FILE__) . '/modules/'));
    return $autoloader;
    }
    

    getting back to config you need also to add

       resources.modules[] = ""    
       resources.frontController.defaultModule = "admin" 
    

    here is my complete config file :

    phpSettings.display_startup_errors = 0
    phpSettings.display_errors = 0
    includePaths.library = APPLICATION_PATH "/../library"
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    appnamespace = "Application"
    resources.frontController.defaultModule = "news"
    resources.frontController.prefixDefaultModule = 1
    resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
    resources.modules[] = ""
    ;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
    resources.frontController.params.displayExceptions = 1
    resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
    autoloaderNamespaces[] = "xxxxxx"
    
    resources.db.adapter = "Mysqli"
    resources.db.isdefaulttableadapter = true
    resources.db.params.host = "localhost"
    resources.db.params.dbname = "xxxxx"
    resources.db.params.username = "root"
    resources.db.params.password = "root"
    resources.db.params.charset = "utf8"
    

    hopefully i didn't miss any thing

    0 讨论(0)
  • 2021-02-11 05:51

    What just fixed it for me was to add the following line to application.ini

    resources.modules[]=

    Then i added a Bootstrap.php to the module directory ('application\modules\books\')

    class Books_Bootstrap extends Zend_Application_Module_Bootstrap {
    
        protected function _initAutoload()
        {
          $autoloader = new Zend_Application_Module_Autoloader(array(
               'namespace' => 'Books_',
               'basePath' => dirname(__FILE__)
          ));
          return $autoloader;
         }
    }    
    

    Move the books model to 'application\modules\books\models\Books.php'

    class Books_Model_Books extends Zend_Db_Table_Abstract {...}
    

    Now you should be able to load the model in the IndexController

    $model = new Books_Model_Books();
    
    0 讨论(0)
  • 2021-02-11 06:11

    The correct class name would be Books_Model_Books, but the filename of that class would need to be Books.php (note the capital 'B').

    You shouldn't have a bootstrap in the modules directory, but you probably do want a bootstrap for each module directory, so you'd need a class:

    class Books_Bootstrap extends Zend_Application_Module_Bootstrap
    {
    
    }
    

    at: application/modules/books/Bootstrap.php (again note the capital 'B').

    Check the section on the module resource autloader at http://framework.zend.com/manual/en/zend.loader.autoloader-resource.html for more info.

    0 讨论(0)
  • 2021-02-11 06:13

    In the application.ini, add a simple line:

    resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
    

    and in the method _initAutoload() inside the Bootstrap put:

    $front = $this->bootstrap("frontController")->frontController;
    $modules = $front->getControllerDirectory();
    $default = $front->getDefaultModule();
    
    foreach (array_keys($modules) as $module) {
        if ($module === $default) {
            continue;
        }
    
        $moduleloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => $module,
            'basePath'  => $front->getModuleDirectory($module)));
    }
    

    make sure the name of models inside each module are like

    [name_module]_Model_[name_model]
    

    in you case, like

    class Books_Model_Books {
    }
    

    and that's all :D

    0 讨论(0)
提交回复
热议问题