且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是大型网站最可扩展的基于PHP的目录结构?

更新时间:2023-12-03 18:51:04

这是我的设置。对于小型非常大型的项目(包括社交网络),这对我来说非常棒。

这些文件夹都将存在于我的主要应用程序文件夹中:




  • 配置 - 包含自定义PHP配置文件


  • css - 包含项目的CSS文件


  • helpers - 包含'帮助'文件(每个文件是函数的集合)


  • 图像 - 包含项目的图像


  • js - 包含项目的Javascript文件


  • lib - 包含特定于项目的PHP类


  • modules - 我的MVC框架允许将网站部分包装为


    • 博客 - 一个示例模块

      • controllers - 包含模块的控制器

      • models - 包含模型对于模块

      • views - 包含模块的视图






  • 个视图 - 包含全局可访问的视图(页眉,页脚等)



    • 所有目录显然都可以包含进一步组织文件的子文件夹。例如,'css'文件夹可以具有名为web和mobile的子文件夹。 'images'文件夹可以包含'user_uploaded'文件夹,然后可以包含''profile'。当然,您可以根据需要添加文件夹,在一个项目中,我有一个名为上传者的文件夹,它只包含独立的上传脚本。



      我还使用方便的方法来帮助构建我要加载的文件名。例如,我的loadView()将在当前模块目录中查找视图文件,或者如果传递了一个可选的$ module参数,那么它将特别在该模块的文件夹中。



      我希望这有帮助。


      I am creating a very large PHP MVC-based site that will have a large library of php classes, javascripts, and many css files (not to mention a large amount of files for the MVC).

      For the first time ever, I am actually taking the time to plan out a clean and organized directory structure.

      What directory structures do you typically use, and which will be easiest to manuever when there are thousands of files?

      This is my setup. It's worked great for me for small - very large projects (including a social network).
      These folders would all live within my main application folder:

      • config - contains custom PHP config files
      • css - contains the project's CSS files
      • helpers - contains 'helper' files (each file is a collection of functions)
      • images - contains the project's images
      • js - contains the project's Javascript files
      • lib - contains PHP classes specific to the project
      • modules - My MVC framework allows packaging site sections as modules
        • blog - An example module
          • controllers - contains the controllers for the module
          • models - contains the models for the module
          • views - contains the views for the module
      • views - contains views that should be globally accessible (page header, footer, etc)

      All the directories could obviously contain sub-folders that would further organize your files. For example, the 'css' folder could have sub-folders named 'web' and 'mobile'. The 'images' folder could contain a 'user_uploaded' folder which could then contain`'profile'. And of course you can add folders as you see fit, in one project I have a folder called 'uploaders' which just contains stand-alone upload scripts.

      I also use convenience methods which help construct the filenames of what I want to load. For example, my loadView() will look for the view file in the current module directory, or if you pass an optional $module argument, it will look specifically within that module's folder.

      I hope this helps.