logo       
Google Custom Search
    AddThis Social Bookmark Button

Re: Re: CGI::App::DBH or Ima::DBI: msg#00141

Subject: Re: Re: CGI::App::DBH or Ima::DBI
Michael Graham wrote:
As a newbie to Class::Application, I'd be interested in learning what
templating language you use with Class::DBI.  I'm still trying to decide
on the best approach.  Because CDBI uses accessors for all data, it
seems to me that HTML::Template would be a lot of extra work.

Yes, Class::DBI works much better with TT2 than it does with HTML::Template. But as with using Class::DBI over DBI you are trading performance for convenience.

Personally I have started using TT2 for my CGI::App projects, as it makes my code much simpler while still keeping the templates simple as well. I make it a rule to only use the simplest features in TT2 (no perlcode in the templates, simple foreach loops and if statements, etc...)

On the other hand, Template::Toolkit's "magic dot" notation would seem
to be ideal here:

    $template->process($input, {
        employee => $employee,
    });

    # This allows the following template to "just work":

        [% employee.name  %]
        [% employee.email %]
        [% employee.phone %]


And to extend your example even more, if you had a second Class::DBI object defining a department with a has_a relationship from employee to department and department has a manager column that links back to the employee table. Then you could also do something like this in the template.

         [% employee.name  %]
         [% employee.email %]
         [% employee.phone %]
         [% employee.department.name %]
         [% employee.department.manager %]
         [% employee.department.manager.name %]
         [% employee.department.manager.email %]
         [% employee.department.manager.phone %]

And all that is possible without needing to pass anything more than the original $employee object to the template. Class::DBI takes care of pulling the data out of the database if it is needed. So the manager data is not retrieved from the database unless the manager is actually referenced in the template.

I had a look at trying to make HTML::Template support something like the
"magic dot", but it didn't seem to want to bend that way.  Are there
other approaches?  How nicely does Template::Toolkit play with
CGI::Application?

I think someone provided a patch to the HTML::Template mailing list a while ago that implemented this along with some other features. But I don't know if it is really a worthwhile addition to HTML::Template. Its strength is raw speed and simplicity, and it is wildly successful in that goal.

Perhaps if I ever get around to writing up a blurb on how I use Class::DBI in CGI::App, I will include some TT2 stuff as well, since the three really go hand in hand...

Cheers,

Cees


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/cgiapp@xxxxxxxxxxxxxxxxx/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: cgiapp-unsubscribe@xxxxxxxxxxxxxxxxx
For additional commands, e-mail: cgiapp-help@xxxxxxxxxxxxxxxxx





Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>