在另一个模块中找不到Zend-db表


Zend - db table not found in another module

我有一个包含三个模块的应用程序:defaultdisciplinesplans。在disciplines中,我有一个dbtable,它在这个模块中运行良好,但如果我想在plans_dbtable中使用模块plans中的dbtable,我会得到

在C:''examplep''htdocs''proect_mps''application''modules''plans''models''DbTable''plans.php的第43行中找不到类"Discipline _Model_DbTable_Discipline"。

Require_one和include并不能解决问题。我已经编写了Discipines_Boottrap和Plans_Bootstrap类。但它不起作用。有什么想法吗?

class Plans_Model_DbTable_Plans extends Zend_Db_Table_Abstract
{
    ...
    public function addPlan(
        $year,
        $name,
        $code,
        $domain,
        $specialization,
        $years)
    {
     
       // Id-ul disciplinei
       $id_discipline = 0;
       $discipline = new Disciplines_Model_DbTable_Disciplines();
       ....
    }
    ...
}
    

由于您使用的是Zend,我不建议您使用require_one作为最佳答案。基本上,如果您的配置很好,则不需要在任何地方使用require_once。这可能会有所帮助:

在文件application.ini 中

;Module Configuration
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleControllerDirectoryName = "controllers"
; Enables Modules bootstrap resource plugin, so each module directory has a bootstrap.php file
resources.modules = 1

并且在BootStrap.php文件中

protected function _initFrontController() {
        // The Zend_Front_Controller class implements the Singleton pattern
        $frontController = Zend_Controller_Front::getInstance();
        // look in the modules directory and automatically make modules out of all folders found
        $frontController->addModuleDirectory(APPLICATION_PATH . '/modules');
        // forces the front controller to forward all errors to the default error controller (may already be false by default)
        $frontController->throwExceptions(false);
        return $frontController;
    }

是的,你需要有Bootstrap.php为你的每个模块

    class Disciplines_Bootstrap extends Zend_Application_Module_Bootstrap
{
    /**
     * This file is ABSOLUTELY NECESSARY to get module autoloading to work.
     * Otherwise calls to "$form = new Module_Form_MyForm()" will fail.
     */

}

我想我自己已经解决了。我不得不写

require_once(APPLICATION_PATH.'/modules/disciplines/models/DbTable/Disciplines.php');

而不是

require_once '/proiect_mps/application/modules/disciplines/models/DbTable/Disciplines.php';

这也起作用:

require_once('/../../../disciplines/models/DbTable/Disciplines.php');

用于我的文件夹结构。