tags:

views:

919

answers:

5

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?

+1  A: 

For core files which are included: approot/inc/

For data access functions and classes are in: approot/dao/

For javascripts: approot/scripts/

For CSS: approot/styles/

For images: approot/img/

For static content (normally for user profile pictures or uploaded images): approot/static/

For caches: approot/caches/

For templates or View files: approot/templates/

All pages file: approot/

Structure from Samstyle PHP Framework

thephpdeveloper
why did this one get voted down?
johnnietheblack
no idea. would love to find out from voter as well.
thephpdeveloper
+1  A: 

In my experience, you can never plan for this. You can try to follow what frameworks do, but I find I never quite fit exactly into their mold.

I recommend to just keep a good rule of thumb for 20 files in a directory maximum. If you find you need more, just create a few sub directories and move common components in there.

Paul Tarjan
cool idea on learning from frameworks...but what are some good ones, and where do i find their structures? thanks!
johnnietheblack
+3  A: 
Arms
This means all php code, configuration, etc will be visible to everyone unless you do some server magic with something like .htaccess
OIS
OIS is correct. In this setup, if someone knew the file name, they could call it from the browser. I posted this answer before switching to Symfony (which hides all background files) and I definitely recommend moving all non-public files outside of public web access.
Arms
+1  A: 

I use codeigniter for small and big projects. It's MVC feature is moderately good.

  • codeIgniter\system\application\config : contain all kind of configuration files like DB,Payment gateway, ftp config, routes and ...
  • codeIgniter\system\application\models: contain all kinds of database classes, you should create sub folders according to your need, I used customers, mailData, paymentModel, report, web-service and ....
  • codeIgniter\system\application\views: contain all kinds of files that will work as output for clients, you should think of reuse these files if possible. Like the models you had to create sub folder like administration, reports, email, email_template .....
  • codeIgniter\system\application\controllers : this is the most important part. This will help to create SEO url, so you should be more careful about sub folders this time. You can create like administration, products, reports, orders..... and consider a good name for the functions of the controller class.

These were for the PHP/HTML file.

Now about the other files:

  • codeIgniter\images: for the images
  • codeIgniter\scripts: for the Java scripts and their framework
  • codeIgniter\styles: for the CSS
  • codeIgniter\uploads: for the uploaded files, if you don't want to put files in the DB

For the detail see codeIgniter framework in detail.

Here "codeIgniter\" is the approot

Imrul
+3  A: 

You should have one directory as web root, where only files you want exposed to the whole internet should reside.

project/
 web/
  index.php
  css/
  js/
  images/
 config/
 lib/
  • web/ is the root shown to visitors
  • lib/ is here the library folder, and where autoload look for files.

You can add more subfolders to project/ like controller, modules, view, helper, etc. This depeds on your framework.

OIS
Clean and simple but lacks two important folders: `project/tests/` and `project/class/` (so that the `lib` folder can be used for third party libraries). May be you people have other suggestions for the thrid parties structure?
Wernight