Bruce W...1 wrote:
I've been learning about PHP for a couple of weeks. With includes, PHP
scripts, and HTML I can see where a large and complex website could
easily turn in to a big hairy mess with files all over the place.
been there, done that.
Are there any adopted standards, recognized recommendations, or best
practices on how all the code should be organized? I haven't found any
websites that discuss this.
Nor have I.
Can anyone point me to information on this? If not then what do you do,
i.e. if you are organized?
Over the years I have developed a library of functions and classes I've
used in project before. In that last year, I started to create myself a
CMS system to organize all this stuff and make me more efficient at
putting things together.
The way I organize things now is as follows:
config.ini.php: This file holds all the settings that I will be using
throughout the project. (Database connection details, image sizes, email
headers, etc.)
template.php: Parses config.ini.php and creates a configuration array,
initializes the database connection through db abstraction (usually
Metabase), and sets up an object of a class that holds the database
connection as well as some other helpful functions (like a formatHTML
function that pulls from the database, searches for HTML/non-HTML and
combines them for display). This file also parses the URI and/or
QueryString to find where in the database to look for the information.
Depending on what that URI/QueryString needs, other files may be
included. output buffering is used to store all the page's output into a
collection of variables.
include/*: This directory holds a collection of files that will be
included in the project somewhere. For instance, in my CMS, you will
find files like: normal.inc.php, news.inc.php, staff.inc.php, etc. - one
for each type of page supported by the CMS. There are also files like
update.normal.inc.php, etc. - update functions for each of the page
types. You would also find files like form.date.start.php - a file that
looks for a certain date variable, parses it, and creates 3 select menus
(year, month, day).
_site_components/*: In this directory I keep things like the db
abstraction package files, my security system used for the CMS, a folder
for images used on the site, a folder for each css definitions, js
scripts, flash movies, etc.
design.php: This file is included at the end of the template.php file.
This holds the HTML design of the project. Generated displays are then
echo'd where they are needed.
This approach keeps my HTML and PHP separate. Additionally, it keeps
closely-related control procedures and functions separate from others.
By doing this, I don't have all the code included into all requests,
only the parts that are needed. (Actually, my main class isn't separated
like that, but I've been thinking of doing so.)
Just my $.02
--
Justin Koivisto -
sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.