views:

313

answers:

6

When doing large projects my code seems to get all over the place. How do you guys organize your code?

+2  A: 

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).

Dolph
MVC ... 2? I wasn't aware there was a second version out ;)
Billy ONeal
My bad, MVC Model 2 is a bit Java-specific http://en.wikipedia.org/wiki/Model_2
Dolph
+2  A: 

Also it is a good idea to use framework (I recommend symfony: http://symfony-project.org). It enforces good files organisation.

Ziells
+1 for symfony. Keep in mind it also let's you very easy change the folder structure to your liking using it's extensive configuration files
Chris T
+3  A: 

Cake PHP is another good framework to use which follows MVC

http://cakephp.org/

Ganesh Shankar
I don't think he is asking for a framework, but how to organize PHP code in a project.
jpartogi
+1  A: 

Zend Framework (http://framework.zend.com/) has a powerful MVC framework.

nute
+1 Zend Framework, to me it seems it is a lot more powerful and flexible than CakePHP
Urda
A: 

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.

Donny Kurnia
+1  A: 

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

Avinash