<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3020" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2>Hello,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2>Maybe you should try this... You should know what page your user
wants because they've clicked on a link to display a certain page (or just
default to the first page if parameter doesn't exist which DBIx::Class will
do). So your action should have access to what page to display via
$c->req->params('page'). Then in the controller you get all of the
photo objects for that particular page (notice the ->all method at the end of
the search) and put that in your stash for TT.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2>my $page = $c->req->params('page') || '';</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2>$c->stash->{photos} =
[$c->model('CatapultDB::Photos')->search(</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2> {</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2> 'gallery.id' =>
$selected_gallery</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2> },</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2> {</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2> join =>
[qw/ gallery /],<BR> prefetch => [qw/ gallery
/],<BR> rows =>
2,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2> page =>
$page,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2> }</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2>)->all];</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2>Then in TT code just like you wrote:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2>[% FOREACH photo IN photos -%]<BR>[% photo.gallery.name %]<BR>[% END
-%]</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2>I hope this might help?</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2>Leandro</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=843065617-30122006><FONT face="Courier New"
size=2></FONT></SPAN> </DIV><FONT face="Courier New" size=2></FONT><BR>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT
face="Courier New" size=2>
<HR tabIndex=-1>
</FONT><FONT face="Courier New"><FONT size=2><B>From:</B> Dennis Daupert
[mailto:ddaupert@sbcglobal.net] <BR><B>Sent:</B> Friday, December 29, 2006
22:38<BR><B>To:</B> catalyst@lists.rawmode.org<BR><B>Subject:</B> Re:
[Catalyst] DBIx::Class/TT Pager Question<BR><BR></FONT></FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT></DIV><FONT face="Courier New"
size=2>Leandro:<BR>> you don't need to use Data::Page directly <BR><BR>yes,
you are quite right, I took out the<BR>explicit call to Data::Page; I set rows
=> 2,<BR>and my query gets 2 thumbs. Cool.<BR><BR>>you are setting
$c->stash->{photos} to an <BR>>array reference when you do
<BR>>$c->stash->{photos} = [$c->model( ... ]; <BR>>and then you
are later trying to make a <BR>>method call ->pager() on that array
reference, <BR>>not an object. <BR><BR>With the square brackets, I get an
array ref, <BR>and in my template, I do stuff like:<BR>[% FOREACH photo IN
photos -%]<BR>[% photo.gallery.name %]<BR>[% END -%]<BR><BR>When I take the
square brackets out of the<BR>query, my template doesn't display
anything<BR>anymore. <BR><BR>>See the "Paged Results" section of the
<BR>>DBIx::Class::Manual::Cookbook POD on<BR>>CPAN.<BR><BR>which of
course I'd been trying to beat <BR>into my forehead. Cookbook says:<BR>"you
can return a Data::Page object for the resultset <BR>(suitable for use in e.g.
a template) <BR>using the pager method:<BR><BR>return
$rs->pager();"<BR><BR>So I'm trying to call the pager method from
the<BR>resultset. But translating from the cookbook<BR>example (which is
non-Catalyst centric) to <BR>Cat code, falls the
shadow.<BR><BR>Chisel:<BR>>$c->stash->{pager} =>
$c->stash->{photos}->pager();<BR>>shouldn't this be an assignment
rather than a fat-comma?<BR><BR>Good eyeballs! Yes. <BR><BR>>I think you
need to lose the square brackets, <BR>>and you will probably find you then
have a <BR>>DBIx::Class::ResultSet, which does have the <BR>>pager()
method. <BR><BR>When I do, I get this error:<BR>Caught exception in
Catapult::Controller::Photo::Gallery->display
"DBIx::Class::ResultSet::pager(): Can't create pager for non-paged
rs<BR><BR>Going back to the DBIx::Class Cookbook example, <BR>which is pretty
simple (no joins or anything), do I <BR>have the joins and the row settings in
the right place? <BR>I tried a few combos, and the one that at least doesn't
<BR>throw cat down the stairs is the one I have been
using:<BR><BR> $c->stash->{photos} =
[$c->model('CatapultDB::Photos')->search(<BR>
{<BR> 'gallery.id' =>
$selected_gallery<BR>
},<BR>
{<BR> join
=> [qw/ gallery /],<BR> prefetch
=> [qw/ gallery /],<BR> rows
=> 2,<BR> }<BR>
)];<BR><BR>Much less hair
now,<BR><BR>/dennis<BR><BR><BR></FONT></BLOCKQUOTE></BODY></HTML>