0

I have an application with three modules:default, disciplines and plans. In disciplines I have a dbtable which works fine in this module, but if I want to use the dbtable in module plans inside plans_dbtable I get

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 and include don't solve the problem. I have Disciplines_Boostrap and Plans_Bootstrap classes written. But it doesn't work. Any ideas?

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();
       ....
    }
    ...
}
    
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • I think i've resolved it myself. I had to write **require_once(APPLICATION_PATH.'/modules/disciplines/models/DbTable/Disciplines.php');** instead of **require_once '/proiect_mps/application/modules/disciplines/models/DbTable/Disciplines.php';**. – Sorin Adrian Carbunaru Apr 04 '12 at 13:22
  • it should work without a require statement. Do both of your module bootstraps extend `Zend_Application_Module_Bootstrap` and are they located in the root of your modules? That has always been the cause when I couldn't autoload module resources. – RockyFord Apr 05 '12 at 08:40
  • yes, they extend Zend_Application_Module_Bootstrap and they are in the root of my modules...if require_once made may application work, well, then it's ok for me – Sorin Adrian Carbunaru Apr 05 '12 at 10:42

2 Answers2

0

Since you're using Zend I would not suggest your answer of having a require_once to be the best Basically if you have your configuration nice you dont need to have require_once any place. This might be of a help :

In file 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

and in you BootStrap.php file

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

And yes you will need to have Bootstrap.php for your every module

    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.
     */


}
ro ko
  • 2,906
  • 3
  • 37
  • 58
  • is it a problem if i use "require_once"? – Sorin Adrian Carbunaru Apr 05 '12 at 11:25
  • Well It might solve the problem so dont know if I should be calling it as a problem but then you're doing something that you should not be done. Say you need to access more 10 models from other modules or make it 50 then requiring each one of them how logical is that when you don't really have to do it. I mean that's what frameworks really are for so that you dont have to do those tedious work. – ro ko Apr 05 '12 at 11:51
-1

I think I've resolved it myself. I had to write

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

instead of

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

This also works:

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

for my folder structure.

Michael J. Barber
  • 24,518
  • 9
  • 68
  • 88