views:

105

answers:

6

Give me the best standard way of coding in PHP. where to store my css, php, images etc. How to seperate my folders, How many folders and whats the name of that folder?

+1  A: 
project/web          # web root
project/web/styles   # CSS files
project/web/scripts  # JavaScript or other script files
project/web/images   # images
project/lib          # non-web-accessible code libraries
project/bin          # executables (including utility scripts)
chaos
This is good because you dont have directories with files not intended for access directly by browsers in the web root and thus need to write and maintain so many access specifications. Similar basic layout as I prefer (more like Zend Framework).
OIS
A: 

What I use to do is the next:

-Main php files
-private
  |_private web zone files
-images
  |_image files
-flash
  |_flash files
-script
  |_javascript files
-css
  |_css files

and son on

hope I've helped you

elvenbyte
+1  A: 

There is no best or standard way - that's the exactly kind of knowledge that you can gain from experience of working on projects - it is not something essential that you need before you can start programming - I would even suggest to keep all in the same folder if it's a small app with just couple of files. Really, you'll get your ways with time and experience.

Petrunov
+1  A: 

You are assuming that there is a best way to do that, and there isn't. It is completely dependent on your application architecture and personal preference.

I can give you a couple of generic hints:

  • Organize your public web folder sanely. Have an images/ directory for images, a css/ directory for CSS, and a js/ directory for javascript. Organization of code will depend on your project architecture.
  • If you are using an OO architecture, it's possible to organize your code files so that they are outside of the web root, which gives you an added layer of security should your web server stop rendering PHP properly due to a misconfiguration (it happens).
  • Images should not be stored in a database unless you have a good reason to do so.
zombat
thanks for your support
Rajasekar
A downvote? Care to explain?
zombat
I got your back, Broseph. Good answer.
Lucas Oman
I don't mind downvotes when an answer is *wrong*, but random downvotes are truly irritating.
zombat
+5  A: 

There is no standard. PHP is a language, not a framework, and as with any language, you can organize your project however you see fit.

However, there are some great frameworks written in PHP that have a directory structure and provide tools, etc. For example, Cake PHP and Code Igniter.

Lucas Oman
+1 same answer, different words.
zombat
Throwing in another recommendation for CakePHP. Although PHP is a language and has no 'needed' organization, the MVC framework is a very effective practice and beneficial to learn.
Mark Hurd
A: 

I'm not sure about the "best standard" because I think you'll find it is largely subjective and dependent on other factors e.g. any frameworks you're using and the size of your project.

However, I've tended to stick with the following convention:-

  • images - General app images
  • lib - Class files, library files, dependencies (usually broken down into many sub folders containing the libraries name e.g. lib/events/employee/). Structuring things fairly logically like this makes the use of __autoload() quite handy when it comes to loading your files in.
  • controller - Controller files
  • js - Javascript files
  • styles - Stylesheets
  • tests - Unit tests
  • templates - Again bundled into various subfolders depending on your apps layout.
  • tmp - Moselle nous stuff, junk, logs.

I've noticed the conventions these days to bundle the js/styles/images folder into their own 'public' (rails) or 'static' (django) folders which might also be nicer.

Gavin Gilmour