Michael Cameron wrote:
This may be a silly question but... After the recent discussions on Class::DBI I have started looking at moving from plain DBI but have a question. When using DBI I simply did a fetchrow_hashref and passed the resulting hashref into HTML::Template to have all the columns available as <TMPL_VAR>'s. How can I accomplish the same thing using Class::DBI?
Well, you can't do it that simply with standard Class::DBI. But it's easy enough to add that kind of method to you classes. Just add a new accessor method to get back an appropriate data structure. I would however highly recommend that you look at Template Toolkit if you are wanting to experiment with Class::DBI.
With TT you can just pass in you list of data objects, or just one data object. Then your templates can look this like...
<!-- A list of people --> [% FOREACH person IN people %][% person.last_name %], [% person.first_name %] - [% person.email %]<br />
[% END %]You no longer have to worry about giving your data to the templates in the form the template dictates. It doesn't matter whether 'people' is an array of hashes or objects, it will still work. You can more easily separate your application logic from your display since you're application logic doesn't have to spend time worrying about making the display side happy.
just my opinion,
--
Michael Peters
Developer
Plus Three, LP
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.