1

I am a bit lost right now. I try to establish my own library but the autoloader seems not to be working somehow. This exaple here was the closest I found but all the solutions did not work for me.

This is my folder structure.

-application
 |_modules
  |_vita
   |_controllers
    |_IndexController.php
-data
-docs
-library
 |_ND
 ||_Model
 | |_Vita
 |  |_Vita.php
 |_Zend
-public
-tests

This is my bootstrap.

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 
{    
    ...

    protected function _initAutoloader()
    {
        $loader = Zend_Loader_Autoloader::getInstance();
        $loader->registerNamespace('ND_');
        return $loader;
    }

    ...
}

This is my complete application.ini (I am aware that the autoloaderNamespaces instruction is double with the one in the bootstrap but it does not work with both or each of them alone)

[production]
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"

; automatic loading of libraries 
autoloaderNamespaces[] = "ND_"

phpSettings.date.timezone = "Europe/Berlin"

;resources.frontController.controllerDirectory = APPLICATION_PATH "/modules/index/controllers"
;resources.frontController.params.displayExceptions = 0

;appnamespace = "Application"
resources.frontController.moduleDirectory            = APPLICATION_PATH "/modules"
resources.frontController.params.prefixDefaultModule = true
resources.frontController.defaultModule              = "index"
resources.frontController.throwerrors                = false
resources.frontController.params.displayExceptions   = 0

; resources (modules)
resources.modules[] = ""
resources.view[]    = ""


; resources (layout)
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout     = "main"

; db settings
resources.db.adapter           = "PDO_MYSQL"
resources.db.isDefaultAdapter  = true
resources.db.params.host       = "localhost"
resources.db.params.username   = "root"
resources.db.params.password   = ""
resources.db.params.dbname     = "nd"

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

This is my Controller where I try to instantiate the class "Vita" But I always receive this Error: "Fatal error: Class 'ND_Model_Vita_Vita' not found in C:\xampp\htdocs\ND\application\modules\vita\controllers\IndexController.php on line 17"

class Vita_IndexController extends Zend_Controller_Action
{
    public function init()
    {
        $this->view->headTitle('Vita');
    }

    public function indexAction()
    {
        /* Just to try if the Loader is working for the Zend library -> it works */
        $this->newForm = new Zend_Form();


        $this->mdlVita = new ND_Model_Vita_Vita();
        Zend_Registry::get('log')->info($this->mdlVita->test());
    }
}

And this is the Vita Class

class ND_Model_Vita_Vita
{
    public function test()
    {
        return 'Is working';
    }
}

Is there something I might have overlooked or I have to have in mind when using modules? I am thankful for any suggestion.

EDIT : I narrowd down the issue to have something to do with the xampp environment. I pushed the project to a live-apache location and there it worked.

Community
  • 1
  • 1
Andy Killat
  • 91
  • 1
  • 4
  • Can't see any obvious problem with the code you posted. Can you confirm whether or not the bootstrap function is being run? Does the error message show the value of the include_path? – Tim Fountain Apr 19 '14 at 21:52
  • By echoing this function: Zend_Loader_Autoloader::getInstance()->getRegisteredNamespaces() I can see the array like that: array( [0] => 'Zend_' [1] => 'ZendX_' [2] => 'ND_' ) So the function is performed and the namespace has been added. – Andy Killat Apr 19 '14 at 22:59
  • The include_path is not displayed. The message I posted is the only one displayed. If I do a typo on purpose I get an error message with the include_path. I call the class as this: "ND_Model_VitaX_Vita" – Andy Killat Apr 19 '14 at 23:03
  • Warning: include_once(ND\Model\VitaX\Vita.php): failed to open stream: No such file or directory in C:\xampp\htdocs\ND\library\Zend\Loader.php on line 134 Warning: include_once(): Failed opening 'ND\Model\VitaX\Vita.php' for inclusion **(include_path='C:\xampp\htdocs\ND\application/../library;C:\xampp\htdocs\ND\library;.;C:\xampp\php\pear\PEAR')** in C:\xampp\htdocs\ND\library\Zend\Loader.php on line 134 Fatal error: Class 'ND_Model_VitaX_Vita' not found in C:\xampp\htdocs\ND\application\modules\vita\controllers\IndexController.php on line 18 – Andy Killat Apr 19 '14 at 23:04
  • Maybe permissions on either the class file or the folders within `library`? – Tim Fountain Apr 20 '14 at 09:45
  • Well I don't know if the permissions somehow got messed up with the xampp environment. Now I set up a virtual machine with an ubuntu and within this environment everything works well. But thanks for all your suggestions. – Andy Killat Apr 20 '14 at 21:37

0 Answers0