Location: PHPKode > scripts > PersistentObject > persistentobject/customer_class.php
<?php
/**
  * @Author:  Paul Campbell <hide@address.com>
  * @Company: Campbell Multimedia <www.campbell-multimedia.com>
  * @Date:    2nd July 2003
  */

/** Simple Customer Class as example subclass usage of 
  * PersistentObject
  */

class Customer extends PersistentObject {
	// Fields should match DB fields, these will be set 
	// by the polymorphic set( "field", "value" ); method 
	// In PerstistentObject class
	var $id;
	var $name;

	// Overrides PersistentObject attribute for DB table.
	// NB:  could also be set with $this->db_table in a constructor
	var $db_table = "customers";

	// Utility function to create a new customer instance ready for storage
	function create( $name ) {
		$this->set( "name", $name );
		$this->set( "id", -1 );
	}
}

/** Simple visual subclass of Customer 
  * Sparing a lecture on OO design principles, 
  * Putting the visual code in a seperate class (or subclass as here)
  * allows you to seperate the "domain" or business/data logic from the
  * method of view.  You can easily create many different views of the 
  * class for different places on the page, or even different protocols
  * eg:  HTML, XML, WML etc.
  */
class CustomerPlain extends Customer {
	function render() {
		print "<p><b>$this->name</b></p>";
	}
}
?>
Return current item: PersistentObject