cvs: pear /DB_DataObject_FormBuilder/examples config_inc.php dataObject.ini index.php
| From: | Markus Wolff | Date: | Mon, 15 Sep 2003 21:09:02 +0000 |
| Subject: | cvs: pear /DB_DataObject_FormBuilder/examples config_inc.php dataObject.ini index.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-12761@lists.php.net to get a copy of this message | ||
mw21st Mon Sep 15 17:09:02 2003 EDT
Added files:
/pear/DB_DataObject_FormBuilder/examples config_inc.php
dataObject.ini index.php
Log:
Initial commit of FormBuilder examples
Index: pear/DB_DataObject_FormBuilder/examples/config_inc.php
+++ pear/DB_DataObject_FormBuilder/examples/config_inc.php
<?php
/**
* This is the standard way of reading in the DB_DataObject configuration file.
* Make sure to include this in all files using DB_DataObject!
*/
// In case we haven't included any PEAR classes yet, we need at least the base class at this
point
require_once('PEAR.php');
$config =
parse_ini_file('/smb_server/apache_docroot/DB_DataObject_FormBuilder/examples/dataObject.ini',TRUE);
foreach($config as $class=>$values) {
$options = &PEAR::getStaticProperty($class,'options');
$options = $values;
}
// Additional instruction for FormBuilder - this is a clumsy workaround, but currently neccessary!
$_DB_DATAOBJECT_FORMBUILDER['CONFIG'] = $config['DB_DataObject_FormBuilder'];
?>
Index: pear/DB_DataObject_FormBuilder/examples/dataObject.ini
+++ pear/DB_DataObject_FormBuilder/examples/dataObject.ini
; Make sure you change the paths and the DSN to match your environment!!
; For more information on DataObject settings, visit the PEAR website.
[DB_DataObject]
database = mysql://user:password@dbhost/formbuilder
schema_location = /your/path/to/DB_DataObject_FormBuilder/examples/classes/
class_location = /your/path/to/DB_DataObject_FormBuilder/examples/classes/
require_prefix = /your/path/to/DB_DataObject_FormBuilder/examples/classes/
class_prefix =
extends_location = DB/DataObject.php
extends = DB_DataObject
debug = 0 ; set at least to 1 or higher to detect problems!
debug_ignore_updates = 0
[DB_DataObject_Generator]
extends_location = DB/DataObject.php
extends = DB_DataObjectOn
; The FormBuilder settings begin HERE!
[DB_DataObject_FormBuilder]
select_display_field = title
db_date_format = 1
date_element_format = d/M/Y
hide_primary_key = 1
add_form_header = 0
Index: pear/DB_DataObject_FormBuilder/examples/index.php
+++ pear/DB_DataObject_FormBuilder/examples/index.php
<?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
*************************************************************************/
// Read DataObject and FormBuilder configurations
require_once('./config_inc.php');
// Which class to use?
if (isset($_GET['class'])) {
$class = $_GET['class'];
} else {
$class = 'Product';
}
// include that class
include_once('classes/'.$class.'.php');
// make the object
$obj = new $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'])) {
$obj->get($_GET['id']);
}
// Include the FormBuilder class definition
require_once('DB/DataObject/FormBuilder.php');
// Create the FormBuilder object BY REFERENCE and pass the DataObject
$formBuilder =& new DB_DataObject_FormBuilder($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
if ($form->validate()) {
$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.
*/
$listObj = new $class;
$list = null;
// 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
$num = $listObj->find();
if ($num > 0) {
// yes, make a list for later output
$list = '';
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;
} else {
$title =
$listObj->$_DB_DATAOBJECT_FORMBUILDER['CONFIG']['select_display_field'];
}
// get the primary key
$keyField = strtolower($class.'_id');
$id = $listObj->$keyField;
// make the list entry
$list .= sprintf("<a
href='index.php?class=%s&id=%s'>%s</a><br />", $class, $id,
$title);
}
}
}
// Some HTML for nice output, inline for simplicity
?>
<html>
<head>
<title>DB_DataObject_FormBuilder Example</title>
<style type="text/css">
<!--
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; }
-->
</style>
</head>
<body>
<h1>Table/Class: <?php echo($class); ?></h1>
<div class='classes'>
<a href='index.php?class=Category'>Categories</a><br />
<a href='index.php?class=Manufacturer'>Manufacturers</a><br />
<a href='index.php?class=Product'>Products</a><br />
</div>
<div class='form'><?php $form->display(); ?></div>
<div class='list'><?php echo($list); ?></div>
</body>
</body>