Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most scalable PHP-based directory structure for a large site?

Tags:

directory

php

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?

like image 708
johnnietheblack Avatar asked Sep 07 '09 04:09

johnnietheblack


1 Answers

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.

like image 200
Steven Mercatante Avatar answered Sep 23 '22 23:09

Steven Mercatante