solidcodes — 2007-08-27T07:56:23-04:00 — #1
Actually i want my PHP codes to be professionally organize,
Yeah, i can understand OOP, but how do you organize them properly?
Let say i have a very very BIG project, now what do you do for your first step
to organize your php script? then the second step,the third step and so on.
I want to hear your experiences.
How do you also organize the files and folders?
Thanks in advance.
bj_duncan — 2007-08-27T08:22:58-04:00 — #2
As much as I love computer technology, nothing beats good old fashioned pen and paper.Before I even touch a keyboard I put everything on paper.
Much like database method I organise things into segments / sections generally by definition of category, depending on the particular project and the clients needs.
sebulbus — 2007-08-27T09:31:12-04:00 — #3
I keep my things one class per file, names className.class.php, similar classes grouped in a subfolder (if there are more than one), all subfolders in a classes folder which I place in the include path.
If I have reoccuring code in files I put that in a common, loader-type file, which I then include everywhere. This sits in a folder of it's own, again in the include path.
Everything related to configuring a script is confined to one array, say $params['this_or_that'], which sits in a config file of it's own, which sits in the include path.
May be difficult to organize at first, but once you have everything figured out, like a blank project it's a simple copy-paste job to start a new one, comment out, or delete what you don't need from the current job in the loader file and start coding.
xaoc — 2007-08-27T10:25:25-04:00 — #4
Take a look at how zend framework is organised. I'm using something very similar - one file per class. Classes are categorised by their types - modules, controllers, views etc. Every
category has its own subfolder in a class directory. As sebulbus said, every configurable thing must be put into one config file. I'm using constants for such things.
Now about a script, try to read some articles about MVC pattern. In a few ford it's a way of programming, when data, it's presentation and logic are separated. Of course, don't forget about OOP principles and always think about what can be reused in other projects, make use of inherintance.
telos — 2007-08-27T11:31:49-04:00 — #5
Typically, I don't put everything in one class. I organize it into smaller classes. for example:
I store all of these in a folder like: lib/php/classes
Then, I use autoloading so that I only include the classes I'm using for that particular script. For example, I don't need to include the MySQL class if I'm not going to make a MySQL query on this page.
Once autoloading is set up, all I need to do is:
$t = new TextArea($var1, $var2, $etc);
Obviously, not all classes will be simple enough to implement in one line. But hopefully you see my point.
Study the PHP classes really good before starting: http://php.net/class
kromey — 2007-08-27T14:39:06-04:00 — #6
Well, I now use MVC using the Zend Framework, so my organization pretty much follows the conventions of ZF now.
Before that, I'd organize all my scripts by what their purpose was:
/ - the root of the application (not necessarily the server's web root)
/bin - all my data processing scripts
/img - images and PHP scripts that produced images would go here
/inc - include files; only config scripts would be in the root of this subdirectory
/inc/classes - my class files (one class per file)
/inc/func - function files, grouped by type (i.e. similar functions in one file)
/template - my template files
All the scripts that the user would ever see would be in the application's root; while for particularly large projects this sometimes got a little out of hand, for most projects this organization worked very well for me.
solidcodes — 2007-08-27T20:29:01-04:00 — #7
you guys are really advanced.
ethanp — 2007-08-27T20:41:42-04:00 — #8
MVC. I also do not use abbreviations for directory titles, so I have things like "include" and "library."
srirangan — 2007-08-27T21:02:18-04:00 — #9
/engine/ stores my controller classes, the business logic of the particular app names the model while the theme is usually also the name of the view.
dvduval — 2007-08-27T23:02:40-04:00 — #10
Do any of you guys ever try to reorganize existing projects that were started by someone else?
contrid — 2007-08-28T01:58:17-04:00 — #11
Get an MVC framework.
It's genius...no, it's beautifully genius.
It does all the work for you.
Creating applications this way will win you peace, honor, women, and money beyond even your wildest fantasies. Simple, isn't it?
xtrem3 — 2007-08-28T02:47:33-04:00 — #12
i do my OOP design as others have mentioned, as for my file structure, i do something like this:
all classes get their own file, and i create subfolders based on whether i need it or not for the current project, but this is just a very minimal base for my projects.
earl_grey — 2007-08-28T04:53:25-04:00 — #13
Using CakePHP here:
[i]/cake[/i] - CakePHP libraries
[i]/app/models[/i] - models, each model is in its own file
[i]/app/views[/i] - views, each controller has its own subdirectory
[i]/app/controllers[/i] - controllers, each controller is in its own file
[i]/app/vendors[/i] - other classes and functions, file per class/library
[i]/app/config[/i] - configuration:
[i]/core.php[/i] - CakePHP and application-specific configuration
[i]/database.php[/i] - database connection configuration
handry — 2007-08-28T08:51:59-04:00 — #14
MVC is the best structured program coding for PHP Scripts.
That is the best user guide that cut off your learning curve.
srirangan — 2007-08-28T09:23:10-04:00 — #15
Code Igniter is a very promising project. It doesn't overdo like most other PHP Frameworks.
jazzslider — 2007-08-28T11:35:16-04:00 — #16
I like to have a folder structure that mirrors the class hierarchy, sort of like is suggested in the PEAR coding standards (but not quite exactly like that, since I kind of feel like it's overkill for a non-PEAR project). Since I don't usually have too many levels of inheritance, it works sort of like this (folders in square brackets, files otherwise):
One thing, however, doesn't seem to fit very well into this system: interfaces! Since a class can implement more than one interface, it's not really possible to store classes in folders based on their interfaces alone. So where do the interface files go?
So far my answer has always been to put them in a separate folder independent of the [classes] folder. I.e.,
--(see above for structure)
This seems kind of messy to me, but I haven't had any better ideas yet. Any suggestions?
bludragon — 2007-08-28T13:13:07-04:00 — #17
I usually do one class/interface/function per file using the name as the file plus ".php". I don't use ".class.php" or anything like that because if "class" suddenly becomes "interface" I don't want to have to keep renaming my files (just being lazy I guess).
As far as directory structure goes:
[Basic framework classes, abstract classes, interfaces, etc]
[SQL files, XML files, etc]
[SQLite database (*.db) files]
[YAML, XML, INI, etc files - one per area/category (main.yml, db.yml, etc)]
[Libraries/code that I did not write]
The directory structure is pretty much a modified version of the one RoR uses.
dachande663 — 2007-08-28T13:21:09-04:00 — #18
By comparison I keep mine pretty simple:
and that's pretty much it.
nextsite — 2007-08-28T13:53:44-04:00 — #19
I like Code Igniter as well, and want to get into it, I haven't learned it yet, but the tutorials are nice and easy to learn.
I've also heard good things about CakePHP so might check that out as well.
dan_grossman — 2007-08-28T17:33:05-04:00 — #20
CI and Cake are trash compared to Symfony.
next page →