dlw*_*est 15 php architecture model-view-controller
我正在努力清理我一直在努力的框架.现在,该站点包含以下目录:
Models
Views
Controllers
Helpers (Miscellaneous functions)
Libraries (Universal classes, like library and session management)
Images
Style
Run Code Online (Sandbox Code Playgroud)
无论何时调用页面,路由器脚本都会查找关联的控制器,因此site.com/login将在'/controllers/login.php'实例化Login_Controller.我遇到的问题是,路由器脚本本身就像一个类型控制器和view.php一样,它处理由适当视图处理的格式化数据.但这些并不像页面控制器,因为它们控制着MVC本身.我对这个架构还是有些新手,我很好奇有经验的人会如何组织这个.
我可以将路由器和视图控制器分类为库,还是最好在/ controllers中创建一个名为'pages'的子目录,还是其他任何想法?非常感谢.
Pac*_*cer 18
我建议你研究一下框架的目录结构,比如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)
...
Run Code Online (Sandbox Code Playgroud)
您还可以使用文件命名约定,例如:YourClassName.class.php用于clases,YourView.phtml用于您的视图等.检查框架,您将学习如何很好地构建和应用程序.
我建议遵循Symfony 1.x目录结构.清晰,合乎逻辑,安全.
摘自Fabien Potencier和FrançoisZaninotto的书"Symfony权威指南":
apps/
frontend/
backend/
cache/
config/
data/
sql/
doc/
lib/
model/
log/
plugins/
test/
bootstrap/
unit/
functional/
web/
css/
images/
js/
uploads/
Run Code Online (Sandbox Code Playgroud)
我不会称自己为专家,但一个解决方案是将您的"框架"从实施中移开.我的意思是将您的'router','view.php'和其他框架类移动到某个外部位置,然后将其包含在index.php或任何文件中作为您的访问点.
然后,只有内容位于您的实际应用程序目录中,而所有框架文件都位于无法通过Web服务器访问的位置.
只是一个想法:)