MVC 的目录结构

2024-01-29

我正在尝试清理我一直在研究的框架。目前,该站点由以下目录组成:

Models
Views
Controllers
Helpers (Miscellaneous functions)
Libraries (Universal classes, like library and session management)
Images
Style

每当调用页面时,路由器脚本都会查找关联的控制器,因此 thesite.com/login 会在“/controllers/login.php”处实例化 Login_Controller 我面临的问题是,路由器脚本本身感觉像是一种类型控制器,就像 view.php 一样,它处理要由适当视图处理的格式化数据。但它们不太像页面控制器,因为它们控制 MVC 本身。我对这个架构还是有点陌生​​,我很好奇有更多经验的人会如何组织这个。

我可以将路由器和视图控制器分类为库,还是最好在 /controllers 内创建一个名为“pages”的子目录,或者任何其他想法?非常感谢。


我建议你研究一下框架的目录结构,例如 symfony2 或 yii

这是我为自己选择的:

public_html/              (for public files) (should be public, place only index.php in here)
public_html/css/
public_html/images
public_html/js            (for your js files, or custom generated ones)
lib/                      (for my libs)  (should be private)
lib/vendor/               (for 3rd party libs)
application/              (for the whole app) (should be private)
application/class         (classes that make the app work such as mainApp, Controller, Model, View, etc...)
application/class/model   (all the models)
application/class/view    (all the views)
application/class/view/html (templates used by the views)
application/class/controller (all controllers)
application/class/helper  (helper functions)
application/class/lib     (libs that you develop for the application)
application/template      (layout and/or templates for the application)
application/conf          (config files)
application/log           (log files)
application/cron          (scheduled jobs)
application/database      (for database migration scripts)
...

您还可以使用文件命名约定,例如:用于类的 YourClassName.class.php、用于视图的 YourView.phtml 等。检查框架,您将了解如何良好地构建应用程序。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MVC 的目录结构 的相关文章

随机推荐