ZendFramework - Where to place additional classes in modular directory structure?

梦想与她 提交于 2019-12-03 21:58:14

Sounds like you want these to go into application/modules/somemodule/models so a class like Somemodule_Model_SomePromotion would reside in application/modules/somemodule/models/SomePromotion.php.

I believe that the default resource autoloader for a modular setup will be configured to load models with classnames of hat format from that models folder. But if not, then add the following into the module (not the app) Bootstrap:

protected function _initResourceLoader()
{
    $resourceLoader = new Zend_Application_Module_Autoloader(array(
       'namespace' => 'Somemodule_',
       'basePath'  => dirname(__FILE__),
       'resourceTypes' => array(
            'models' => array(
                'namespace' => 'Model_',
                'path'      => 'models',
            ),
       ),
    ));
}

Update

Per Comment by @brady.vitrano: If the module bootstrap extends Zend_Application_Module_Bootstrap, then a resource autoloader containing this mapping comes for free. No need to include it manually, unless you wish to add other resource types.

You should structure your own library like this:

/application
    /modules
        // Module structure
/library
    /Package
        /Subpackage
            /ClassName.php
    /Zend
        // Zend Framework Files

Where your class name is Package_Subpackage_ClassName. You should also add your Package_ prefix to the autoloader.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!