Best way tio fulfill form fields with data from database

64 views
Skip to first unread message

Tomas Schertel

unread,
Jun 14, 2012, 12:48:36 PM6/14/12
to we...@googlegroups.com
What's the best way to populate fields of a page with database information.
Is it passing a database search result (from my controller) as a parameter to my render call (calling my view)?
Is there other ways to do that?
How do you guys do it?

Thanks.

John Fulton

unread,
Jun 14, 2012, 2:05:49 PM6/14/12
to we...@googlegroups.com
I'd get it to one DB row identified by the ID; e.g. "select from foo
where id='id'". The id would be in the URL of the page to be
displayed; e.g. foo?id=1234. Then my class that dealt with displaying
that URL would get the id from web.input (check it for safety:
http://xkcd.com/327/) and then run the query. The output of the query
would then populate a dictionary mapping form field to form value;
you could do this in a separate object which encapsulates the
dictionary. I would then pass that dictionary (or an object with said
dictionary encapsulated) to my render method. Render would call an
HTML template which was populated using HTML like this:

<input type=text name="something" value="$something">

That way if the form is empty $something doesn't display but if
$something contains a value it will be the default value of your form.

John
Reply all
Reply to author
Forward
0 new messages