Re: Package proposal: DataObjectOnSpeed (naming is discussable :-))
| From: | Alan Knowles | Date: | Wed, 23 Jul 2003 01:27:58 +0000 |
| Subject: | Re: Package proposal: DataObjectOnSpeed (naming is discussable :-)) | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-18565@lists.php.net to get a copy of this message | ||
Just one thought.. - would it be better to use a wrapper pattern on this rather than just straight extension.
$do = DB_Dataobject::factory('mytable');
$x = new DB_DataObject_QuickForm($dataobject,array(
'target' => '_self',
'method' => 'post'
);
$form = $x->getForm();
where the constructor does:
function DB_DataObject_QuickForm(&$do,$options) {
$this->dataObject = $do;
$this->options = $options;
}
you can always use
function &_generateForm($options)
{
global $_DB_DATAOBJECT;
include_once ("HTML/QuickForm.php");
$do = &$this->dataObject;
to prevent having to type $this->dataObject each time..
This would make it totally neutral of adding to the inheritance tree..
and follows DB_DataObjects kind of unwritten rule of not having more than 3 arguments to a method.
---
I guess one of the problems is that _get_keys() is hinted as private, I think for all intense purposes this hint should be ignored. and perhaps changing it's name is an idea. (object vars are a different case as its prefixed to prevent clashes with database columns)
Regards
Alan
Markus Wolff wrote:
Hey guys, as mentioned a few days ago, I´ve written a class that acts as a bridge between DB_DataObject and HTML_QuickForm, which makes it very suitable for rapid prototyping of applications. - It can auto-generate fully functional forms out of your DataObject-derived classes. - It will try to auto-detect the field types and choose appropriate form element types for them. As this sometimes is not possible out- of-the-box, this can be influenced by setting some new config properties in your classes. - It will try to set up some *very* basic validation rules based on the field´s datatype. If you need to add to or alter these rules, you can do so after auto-generation. - It will automatically follow table relations to build select boxes (if the links.ini file is correctly configured). - It allows you to start out prototyping quickly using generated forms and then customizing the form elements step-by-step until you´re satisfied with the outcome. You can mix user-defined element definitions with auto-generated ones, so you only need to do the minimum amount of neccessary work (yes, I am lazy - that´s why I´ve written this ;-)) - It provides a standard method for processing incoming form data and for automatically performing an insert or update on the database with that new data. - It can not yet make coffee :-((( The code can be seen here: http://projects.21st-hq.de/DataObjectOnSpeed.phps When using this class, making a form *and* performing the appropriate insert or update operations for some table data looks as simple as this: include_once('DataObjects/Customers.php'); $cust = &new Customers; if (isset($_GET['customer_id'])) {-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.com$cust->get($_GET['customer_id']);} $form = $cust->getForm($_SERVER['PHP_SELF']); if ($form->validate()) {$form->freeze(); // This will automagically insert or update the data $form->process(array(&$cust,'processForm'), false);} $form->display(); That´s all. The name of the class is more like a working title ;-) Realistically, I´d be for DB_DataObjectUtils - I wouldn´t like to have any reference to "Form" or "QuickForm" in the name, as I might add some more utility functions in the future that are not related to form generation. Opinions, votes? :-) CU Markus