该模型不是一个类或任何单个对象。这是一个非常常见的错误,因为大多数框架会使这种误解持续存在。PHP MVC文件夹结构/模型文件夹结构
那么,什么是模型的最佳文件夹结构?
例如,Zend Recommended Project Directory Structure只有一个“模型”文件夹。但是当我尝试将我的模型分成Domain Objects, Data Mappers and Services时,这个结构应该如何?
谢谢!
该模型不是一个类或任何单个对象。这是一个非常常见的错误,因为大多数框架会使这种误解持续存在。PHP MVC文件夹结构/模型文件夹结构
那么,什么是模型的最佳文件夹结构?
例如,Zend Recommended Project Directory Structure只有一个“模型”文件夹。但是当我尝试将我的模型分成Domain Objects, Data Mappers and Services时,这个结构应该如何?
谢谢!
我认为这是主观的,但我会给你我做这件事的方式。我保留models
目录,然后为应用程序的每个模块创建不同的子目录。它看起来像下面这样:
application
- controllers
- models
- authentication
- services
- mappers
- ...
- mail
- services
- mappers
- ...
... (other directories)
- views
- templates
我觉得这给了每个模块的一个很好的分离,同时保持其其他开发人员正确地使用到models
目录中的一切。
我不知道这是否是最好或最有效的解决方案,但我认为正确使用名称空间证明它很容易管理。我还了解到,如果您正确使用SOLID principle
,您几乎可以将不同的目录/模块复制/粘贴到其他项目中,而无需太多的ha。。
我希望这可以帮助你正确的方向。 此致敬礼。
在Zend Framework中,您可以创建可以集成自己模型的“模块”。
application/
configs/
application.ini
controllers/
helpers/
forms/
layouts/
filters/
helpers/
scripts/
models/
modules/
Domain Objects/
controllers/
models/
Data Mappers/
controllers/
models/
Services/
controllers/
models/
services/
views/
filters/
helpers/
scripts/
Bootstrap.php
正如你所看到的,每个模块也有控制器和视图关联。
最后,你必须将这些模型添加到您的引导程序的自动加载磁带机:
// Admin
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH . '/modules/Domain Objects',
'namespace' => 'Domain Objects'
));
$resourceLoader->addResourceType('controller', 'controllers/', 'Controller')->addResourceType('model', 'models/', 'Model');