我有一个包含三个模块的应用程序:default
,disciplines
和plans
。在disciplines
我有一个dbtable,在这个模块中可以正常工作,但是如果我想在plans
里面的模块plans_dbtable
中使用dbtable我得到
Class 'Disciplines_Model_DbTable_Disciplines' not found in C:\xampp\htdocs\proiect_mps\application\modules\plans\models\DbTable\Plans.php on line 43.
Require_once并包括不解决问题。我有Disciplines_Boostrap和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();
....
}
...
}
答案 0 :(得分:0)
因为你正在使用Zend我不会建议你让require_once成为最好的答案基本上如果你的配置很好你不需要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.
*/
}
答案 1 :(得分:-1)
我想我自己已经解决了。我不得不写
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');
表示我的文件夹结构。