Copyright © 2010 Olebox – Shaun Oleson. All Rights Reserved. Snowblind by Themes by bavotasan.com. Powered by WordPress.
I have worked with a number of programming languages as detailed in my initial introduction. I’ve found that PHP seems to be the fastest from planning to launch if building using OOP. Here is a brief overview of PHP Classes. This is extremely basic so that entry level users have a place to start. Feel free to comment should you have any constructive feedback.
It all starts with creating a display page and a class include. I do this to better organize the files, although everything will still function if built within on file.
index.php
<?php include(‘error.php’); ?>
<html>
<head>
<title>| Class Test File Display</title>
</head>
<body>
<?php// we initiate the class
$error=new Error;// we add an error message
$error->insert(‘This is a test error’);if($error->exists()) {
$error->show();
}
?>
</body>
</html>
The Class file looks like this:
error.php
class Error {
// Here we declare the variables. We set the error message to private
// this forces all updates of the error message to be done through the
// insert() class function// The other variables are public, Title allows the title of the error message
// to be changed, if not specified, it uses the default value// The class is used for css purposes, error messages you may want to
// display in red and/or yellow, while success messages may be in green.
private $e_message;
public $title=”There was an error processing your request”;
public $class=”error”;// This function just adds an additional <li> for each error message
// which allows for wasy formatting.function insert($msg) {
$this->e_message .= “<li>”.$msg.”</li>”;}
// This function displays the error message in a ul/li format
// with a bold title.
function show() {
echo(“<div class=’”.$this->class.”‘>”);
echo(“<strong>”.$this->title.”:</strong>”);
echo(“<ul>”);
echo($this->e_message);
echo(“</ul>”);
echo(“</div>”);
}// this function returns true or false based on whether an error
// message was ever inserted
function exists() {
if(strlen($this->e_message) > 0) {
return true;
} else {
return false;
}
}}
?>
The two files above, if included correctly, will allow you to easily globalize your error messages to place them in one error output that is formatted based on css. It’s simple to create and even easier to integrate!

