best way to structure the code
Posted: Mon Sep 24, 2007 11:38 am
I am working on my first 'non trivial' PHP program and I am wondering the best way to structure the code.
I tried using functions and I even wrote my first PHP class.
However I would have dozens of 'global variables' that I don't want to pass back and forth all the time.
My main page now looks like this with many includes, but I am not too happy with this.
Also I have a big mix of php, HTML, and SQL in the same file. Is there a simple way to break these pieces apart?
I tried using functions and I even wrote my first PHP class.
However I would have dozens of 'global variables' that I don't want to pass back and forth all the time.
My main page now looks like this with many includes, but I am not too happy with this.
Also I have a big mix of php, HTML, and SQL in the same file. Is there a simple way to break these pieces apart?
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
// database setup and other constants
include_once('include2.php');
if (!isset($clTableUtilities))
{
$clTableUtilities = new clTableUtilities();
}
// submit form
if ($submit == 'submit')
{
// do some validation
// no errors, perform add/update
if ($error =='N')
{
// add/updates
}
// errors, try again
else
{
// show form again with errors
}
}
// first time in
else
{
include 'listings_add1.php';
}
?>