Re: Reusable form elements with DB_Table and HTML_Quickforms
| From: | Matthew Vickery | Date: | Tue, 17 Oct 2006 10:57:49 +0000 |
| Subject: | Re: Reusable form elements with DB_Table and HTML_Quickforms | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-25480@lists.php.net to get a copy of this message | ||
Hi Mark,
Many thanks for your quick response.
I have adjusted my code as you suggest but I'm still having issues. I'm afraid I'm new to object-oriented programming!
I've pasted the code below and I'm now getting this error:
"Fatal error: Undefined class constant 'id' in C:\Program Files\xampp\htdocs\booking.verve-venues.com\Guestbook.php on line 13"
As a side note do you know of any good object-oriented PHP courses available in the UK? Something my company could send me on or I could do in the evenings?
Regards,
Matthew
Guestbook.php:
<?php
require_once 'Elements_Pool.php';
class Guestbook extends DB_Table {
// Table Schema
var $col = array();
// Constructor
function Guestbook(&$db, $table, $create = false)
{
$this->col = array_merge(
Elements_Pool::id,
Elements_Pool::personal_details
);
parent::DB_Table($db, $table, $create);
}
}
?>
Elements_Pool.php:
<?php
class Elements_Pool extends DB_Table {
// id
var $id = array(
// unique row ID
'id' => array(
'type' => 'integer',
'require' => true
)
);
// Personal Details
var $personal_details = array(
// first name
'fname' => array(
'type' => 'varchar',
'size' => 32,
// form element definition
'qf_label' => 'First Name',
'qf_type' => 'text'
),
// snip: ...
)
// snip: ...} ?> index.php: <?php // basic classes require_once 'DB.php'; require_once 'DB/Table.php'; require_once 'Guestbook.php'; require_once 'Elements_Pool.php'; // create a PEAR DB object $dsn = "mysqli://db_table_user:abc123@localhost/db_table_test_db"; $db = DB::connect($dsn); // set up for the Guestbook and create it // name the table $table = "guestbook"; $auto_create = 'drop'; $book =& new Guestbook($db, $table, $auto_create); $cols = array('id', 'fname', 'lname', 'email', 'signdate'); // create the HTML_QuickForm object $form =& $book->getForm($cols); // display the form $form->display(); ?>