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:
Place this code into the
library
folder. Typically a filelibrary/App/SomePackage/SomeClass.php
wouldcontain the classApp_SomePackage_SomeClass
. Just add the lineautoloadernamespaces[] = "App_"
into yourconfigs/application.ini
file.Create a new folder inside your
application
folder and configure aZend_Loader_Autoloader_Resource
(or its extended classZend_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.
精彩评论