Source for file index.php
Documentation is available at index.php
/*************************************************************************
* As all DataObject-derived classes can be used in exactly the same way,
* we will use only a single, dynamic script for all the tables
*************************************************************************/
// Be unforgiving about ANY errors, warnings or notices!
// Read DataObject and FormBuilder configurations
require_once './config_inc.php';
$class = isset ($_GET['class']) ? $_GET['class'] : 'Product';
require_once 'DB/DataObject.php';
$obj = DB_DataObject ::factory ($class);
// Maybe an existing record was chosen? If yes, fetch it before making the form!
// (If you don't, a new one will be created on form submit)
if (isset ($_GET['id']) && is_numeric($_GET['id'])) {
// Include the FormBuilder class definition
require_once 'DB/DataObject/FormBuilder.php';
// Create the FormBuilder object BY REFERENCE and pass the DataObject
$formBuilder = & DB_DataObject_FormBuilder ::create ($obj);
// Create the form, make sure to always make a REFERENCE to the FormBuilder object!
$form = & $formBuilder->getForm ($_SERVER['REQUEST_URI']);
// If the form was posted and the data has passed all rules,
// apply the changes to the database
$form->process (array ($formBuilder, 'processForm'), false );
* Although not essential for this example, let's make a quick list of the things
* that already are in the database. All entries will have a link that enables
* you to update the records by passing the appropriate ID.
// Do we have enough info on the object to list all records? We need a field to use for displaying the entry...
if (isset ($_DB_DATAOBJECT_FORMBUILDER['CONFIG']['select_display_field']) || isset ($listObj->select_display_field )) {
// look if there are already records in this table
// yes, make a list for later output
while ($listObj->fetch ()) {
// look for the display field in the object
if (isset ($listObj->select_display_field )) {
$titleField = $listObj->select_display_field;
$title = $listObj->$titleField;
$title = $listObj->$_DB_DATAOBJECT_FORMBUILDER['CONFIG']['select_display_field'];
$id = $listObj->$keyField;
$list .= sprintf("<a href='?class=%s&id=%s'>%s</a><br />", $class, $id, $title);
// Some HTML for nice output, inline for simplicity
<title>DB_DataObject_FormBuilder Example</title>
body { font-family: Georgia, Verdana, Arial, Helvetica, Sans-Serif; font-size: 1em; }
h1 { font-size: 1.5em; font-weight: bold; }
.classes { background: #EFEFEF; padding: 5px; margin: 5px; border: 1px solid black; width: 150px; float: left; }
.form { margin-left: 200px; width: 300px; }
.list { margin-left: 200px; background: #EFEFEF; border: 1px dotted grey; width: 300px; }
<h1>Table/Class: <?php echo ($class); ?></h1>
<a href='?class=Category'>Categories</a><br />
<a href='?class=Manufacturer'>Manufacturers</a><br />
<a href='?class=Product'>Products</a><br />
<div class='form'> <?php $form->display (); ?></div>
<div class='list'> <?php echo ($list); ?></div>
Documentation generated on Mon, 11 Mar 2019 15:48:18 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|