Zend 1.12 - autoloading models without Model_ Namespace

360 views Asked by At

I'm using a standard out of the box Zend 1 directory structure and have a model:

applications
    /models
       /Menu
          Core.php

Now I'd like to autoload Core but without having to name the class as Model_Menu_Core but just Menu_Core similar to how Zend libraries are being named from within library directory i.e. Zend_xxxx and not Library_Zend_....

I don't really want to register each namespace separately but just have automatic autoload similar to standard PHP __autoload()

Also, how can I achieve the same for the global library directory

How can I achieve that? Thanks

1

There are 1 answers

0
b.b3rn4rd On

Use Zend_Loader_Autoloader_Resource and add resouce type without namespace, for example:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    /* ... */

    protected function _initAutoloaderResource()
    {
        $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
            'namespace' => '',
            'basePath'  => APPLICATION_PATH));
        $resourceLoader->addResourceType('model', 'models/', '');
    }

    /* ... */
}