I recently did a web interface to a database. I found myself writing some
code that seemed general-purpose. I'm wondering if I reinvented the wheel.

I happen to use HTML::Template, but one could apply this concept to any
web templating system.

What I want is, when generating the web form, to automatically generate a 
hash with all the tables and fields represented both as the data values 
and as html snippets that produce an appropriate input field with an 
appropriate default. Somthing like

{ 'bicyclists' => [ { 'bicycle' => 'Shwinn',
                      'bicycle_edit' => '<input 
name="bicyclists_who_Lance\ Armstrong_bicycle" type="text" 
value="Shwinn">',
                     'who' => 'Lance Armstrong',
                      'who_edit' => '<input 
name="bicyclists_who_Lance\ Armstrong_who" type="text" value="Lance 
Armstrong" >' }

This can be auotmatically generated for all tables; then in the template I 
can use tmpl_vars and tmpl_loops for only those bits of data I want. To 
this basic structure one could add all sorts of nice features; fields 
which in the database are type ENUM might turn into pick lists.

Then, when you read in data from CGI parameters, another function would 
process all the parameters and update the database appropriately. For 
example, if

$cgi->param('bicyclists_who_Lance\ Armstrong_bicycle')

was set to a new value, it would automatically run the SQL update to 
change the bicycle field.

I've invented a long and grody syntax for specifying tables, rows by 
primary key, and fields, but the point is that that is hidden from the 
template designer as well as the programmer in the simplest cases.

I looked at DBIx::CGITables but that seems to be kind of alpha, I wasnt 
able to get it to work.

I have a vague memory of seeing a HTML::Template::DBI somewhere, but it is 
not in CPAN nor anything like it, so I must be hallucinating.

  - Alex Aminoff
    BaseSpace.net
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to