logo       
Google Custom Search
    AddThis Social Bookmark Button

re[2]: OT: Class::DBI passing data to templates: msg#00041

Subject: re[2]: OT: Class::DBI passing data to templates
Thanks for the help.  What I had attempted was to creat a param method and then 
pass the object into the template via associate.  That did not seem to work my 
param method looked like this:

sub param{
  my $class = shift;
  my $name=shift;
  my $val=shift;
  return $class->columns('all') unless $name;
  return $class->set($name=>$val) if $val;
  return $class->get($name);
}

But I am guessing at what columns does, assuming it returns an array of 
columns??

I will try your method

Michael Cameron

---------- Original Message ----------

FROM:      Rhesa Rozendaal <perl@xxxxxxxxx>
TO:        Michael Cameron <mcameron@xxxxxxxxxxxxxx>
DATE:      Fri, 05 Nov 2004 18:33:01 +0100

SUBJECT:   Re: [cgiapp] OT: Class::DBI passing data to templates

Michael Cameron wrote:
> This may be a silly question but...

Not at all. I had the same question when I started to integrate CDBI into 
CgiApp.

> 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?

What I generally do is this: 

(1)    $tmpl->param( map { $_->name => $obj->$_() } $obj->columns );

A quick and dirty way is using the private _data_hash method: 

(2)    $tmpl->param( $obj->_data_hash );

but I prefer (1) over using a private method that may go away.

HTH,
Rhesa

---------------------------------------------------------------------
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>