我正在努力清理我一直在做的框架。目前,该站点由以下目录组成:
Models
Views
Controllers
Helpers (Miscellaneous functions)
Libraries (Universal classes, like library and session management)
Images
Style每当调用页面时,路由器脚本都会查找相关的控制器,因此ite.com/ Login_Controller会在“/controllers/login.php”中将登录实例化。我面临的问题是,路由器脚本本身感觉像是一种控制器,view.php也是如此,它处理要由适当视图处理的格式化数据。但它们不太像页面控制器,因为它们控制着MVC本身。我对这个架构还是比较陌生的,我很好奇有更多经验的人会如何组织这个架构。
我是否可以将路由器和视图控制器归类为库,或者在/controllers中创建一个名为“pages”的子目录更好,或者其他任何想法?非常感谢。
发布于 2011-11-01 06:22:40
我建议遵循Symfony 1.x目录结构。清晰,逻辑,安全。
节选自Fabien Potencier和Fran的书:
apps/
frontend/
backend/
cache/
config/
data/
sql/
doc/
lib/
model/
log/
plugins/
test/
bootstrap/
unit/
functional/
web/
css/
images/
js/
uploads/发布于 2011-11-01 07:23:40
我建议您研究一下框架的目录结构,比如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,等等。查看框架,您将了解如何良好地构建和应用程序。
发布于 2011-11-01 05:16:23
我不会称自己为专家,但一种解决方案是将您的“框架”从实现中移走。我的意思是将你的“路由器”、“view.php”和其他框架类移动到某个外部位置,然后将其包含在index.php或其他文件中作为访问点。
然后,只有内容将在您的实际应用程序目录中,而所有框架文件将位于无法通过web服务器访问的位置。
这只是一个想法:)
https://stackoverflow.com/questions/7959673
复制相似问题