开发者

Directory structure in MVC: Do strategy objects go in models folder?

Which folder should I put strategy objects, or any objects that are not domain models? I'm using Zend Framewo开发者_高级运维rk, if that matters. Appreciate it!


I would use the recommended folder structure laid out here in the Zend Programmer's Reference Guide and place them into the modules folder.


Two pretty standard options:

  1. Place this code into the library folder. Typically a file library/App/SomePackage/SomeClass.php wouldcontain the class App_SomePackage_SomeClass. Just add the line autoloadernamespaces[] = "App_" into your configs/application.ini file.

  2. Create a new folder inside your application folder and configure a Zend_Loader_Autoloader_Resource (or its extended class Zend_Application_Module_Autoloader) with appropriate appnamespaces, paths, and prefixes.

Using this second approach could go something like this:

protected function _initResourceLoader()
{
    $resourceLoader = Zend_Application_Module_Autoloader(array(
        'namespace' => 'Application_',
        'basePath'  =>  APPLICATION_PATH,
    ));
    $resourceLoader->addResourceType('strategy', 'strategies', 'Strategy');
}

Then a class named Application_Strategy_SomeClass would reside in the file application/strategies/SomeClass.php.

Noe that using Zend_Application_Module_Autoloader - instead of the more generic parent Zend_Loader_Autoloader_Resource - will give you a standard set of autoloader mappings for models, forms, services, view helpers, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜