Question

My zend app is created, everything seems to be in order but every time I try to do something like:

$accProducts = new Application_Models_AccProductsMapper();

Only get:

Warning: include_once(Application/Models/AccProductsMapper.php): failed to open stream: No such file or directory in /home/blah/blah/blah/Loader.php on line 148

however, the AccProductsMapper.php file do exist in such directory, directories within the zend app are all lowercase tough.

I've spend a lot of time looking for something to solve this issue with no good results at all.


Bootstrap.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initDoctype()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_STRICT');
    }

    protected function _initAutoload()
    {
        $moduleLoader = new Zend_Application_Module_Autoloader(array(
            'namespace' => '',
            'basePath' => APPLICATION_PATH));
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->registerNamespace(array('App','My_'));
        return $moduleLoader;
    }
}
Was it helpful?

Solution

The standard Zend_Loader_Autoloader_Resource class added to each module looks for models with the class prefix <ModuleNamespace>_Model_ in <module-directory>/models.

For the default module, the namespace is defined in your config's appnamespace property (defaults to Application). The directory is typically application.

To summarize, create your default module model classes in application/models with class prefix Application_Model_, eg

<?php
// application/models/AccProductsMapper.php

class Application_Model_AccProductsMapper
{
    // etc

As for your _initAutoload() method, I can't tell what you're doing with that module loader and would advise you don't need it at all. You can register PEAR style namespaces in your config file, eg

autoloadernamespaces.App = "App_"
autoloadernamespaces.My = "My_"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top