gpt4 book ai didi

model-view-controller - MVC 的目录结构

转载 作者:IT王子 更新时间:2023-10-29 00:20:55 25 4
gpt4 key购买 nike

我正在尝试清理我一直在使用的框架。目前,该站点包含以下目录:

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

任何时候调用一个页面,路由器脚本都会查找关联的 Controller ,所以 thesite.com/login 会在 '/controllers/login.php' 实例化 Login_Controller 我面临的问题是,路由器脚本本身感觉就像一种 Controller ,view.php 也是如此,它处理格式化数据以由适当的 View 处理。但它们并不完全像页面 Controller ,因为它们控制 MVC 本身。我对这个架构还是有些陌生,我很好奇有更多经验的人会如何组织这个。

我可以将路由器和 View Controller 归类为库,还是在/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 用于您的 View 等。检查一个框架,您将学习如何很好地构建应用程序。

关于model-view-controller - MVC 的目录结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7959673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com