For simplicity's sake, this example will not be based on a perfect
object model, as I'd have to explain the base classes and how the
other objects extend those base objects. I think this example will still
give you the general idea.
Example HTML Lib
<?php
//connect to database
require ("database.php");
//common utils like header/footer HTML
require ("html.php");
//data access library
require ("bug_data.php");
echo site_header("Page Title");
echo "<H4>Updating A Bug</H4>
<P>";
if (bug_data_update($field1,$field2,$field3)) {
echo "<H3>Update Failed!</H3>";
} else {
echo "<H3>Updated Bug Successfully</H3>";
//echo the global error string
echo $feedback;
}
echo site_footer();
?>
Example Data Access Lib
<?php
/**
*
* controls access to updating a bug in the
* database. Validates data and checks security
* Returns true on success, false on failure
*
*/
function bug_data_update ($field1,$field2,$field3) {
//global string to report back errors
global $feedback;
//$field1 and $field2 are required
if (!$field1 || !$field2) {
$feedback="Field 1 And Field 2 Are Required";
return false;
}
//make sure this user has permission to update
if (!user_isadmin()) {
$feedback="You Must Be An Admin To Update a Bug";
return false;
}