[thelist] PHP Organization

Beau Hartshorne beau at members.evolt.org
Wed Jul 10 13:44:00 CDT 2002


Hi,

I'm trying to figure out a good way to organize all of my .php code. I'd
also like to find a good way to write it so that it's easy to
understand, and then modify later.

Until now, I've kept most of my code in large files. It doesn't take
long before this gets really messy, then later hard to read and modify.
Part of this massive file would have some code that printed out a form,
some code that checked the form's contents once it was submitted, and
some code to insert this information in a database.

Instead, I'd like to keep smaller chunks of code seperated in different
.php files, and use one "brain" .php file per major section (product
catalogue, contact, etc) to figure out which of the smaller .php files
to include. I think a good way to organize this would be to keep
separate directories for each section, and keep all of the .php files
that are unique to that section in their directory. The "brain" .php
file would be the index.php file inside whatever directory. So, the
directory structure would look something like this:

/index.php
/contact/index.php
/contact/print_contact-form.php
/contact/check_contact-form.php
/contact/update_contact-database.php
/products/index.php
/products/show_catalogue.php
/products/show_item.php

etc...

There will probably be a few things that the entire app would need
access to. They could be kept in a /global directory.

Another advantage is that you could code links like this:
<http://www.foo.com/bar/> instead of: <http://www.foo.com/bar.php>.

Does anyone see any potential problems with this structure? Can anyone
make any suggestions to make it better?

Thank you,

Beau





More information about the thelist mailing list