Class "message"
  • Author: Marco Voegeli, www.voegeli.li
  • License: Freeware
  • Purpose of this script: The class "message" provides a simple and object oriented way to handle errors in php scripts. it handles also the way, the message is written to the client (output). The object can have one or N message types and lines. So it can also be used as a protocol. It is very easy to use, please check the following example.
Methods
Following, the methods of this class are explained:
Method Description
message() Constructor (private): No parameters possible
clear() Clears the message table (unset)
add(type,text) Adds a new message to the table.

type:

  • "I", Information
  • "W", Warning
  • "E", Error
  • "S", Success
  • "D", Stop

text: 

Contains the message text you want to output

write(header) Writes the message table to the client (output).

header:

  • "", No header output
  • "X", Header output: "Number of Messages: X"

Sample Output:

haserrors() Delivers true, if one or more error messages are in the table (else: false)
haswarnings() Delivers true, if one or more warning messages are in the table (else: false)
Class Configuration
Modify the following constants in the class:
  • const_path: This is the path for the message-images.
Example Usage
Following you find an example of the usage of this class:

<?php

include_once '../class.message.php';

$msg = new message();


$msg->add("I","Info"); 
$msg->add("E","Error");
$msg->add("W","Warn");
$msg->add("S","Success");
$msg->add("D","Stop");


$msg->write(""); 

?>