When doing large projects my code seems to get all over the place. How do you guys organize your code?
You should be using a design pattern; consider starting with MVC.
Strictly following a design pattern will improve the readability of your code base immensely (among other benefits).
Also it is a good idea to use framework (I recommend symfony: http://symfony-project.org). It enforces good files organisation.
Cake PHP is another good framework to use which follows MVC
Zend Framework (http://framework.zend.com/) has a powerful MVC framework.
Since I use CodeIgniter to build the web application in all my projects, I just follow the framework's guideline.
To put a support file (css, js, and image files), I usually split it into 2 directory. For a global support files, I put it in public dir:
public
|--> css
+--> images
`--> js
For a page template, I usually got this from a partner or my client provided it. I will put all the files into styles/front
and styles/admin
directory. I'm not changing any arrangement of images, js, and css inside these directory, so I can put any updates directly to it.
I am using below structure and it works fine for me...
--> Class
--> Action
--> Middle
--> Js
--> Css
--> inc
Above is the folder structure i am using.
There will be four files for each file.
One file at root. in which all other files will include and other configuration files also included.
In Class Folder:
All the classes for any page will be here.
So all DB operation will be here.
In Action File
All the action and method calling will be here.
When any form post. First it will check for action in this file.
And based on action it will call the function which is in class file.
In middle File
All files in this folder will contain the dynamic HTML of the page. Based on action performed in class files HTML will be displayed from here.
In JS folder
All JS related to project will be here.
In CSS Folder
All CSS related to your project will be here.
In INC Folder
All the common files related to your project will be here.
Like
conf.php
sitefunction.php
constant.php