There seems to be a prolem when using this custom paginate function.
the variables like $paginator is not registered which is required for
view. is there any solution to this?
On Feb 20, 7:00 pm, "Chris Hartjes" <[EMAIL PROTECTED]> wrote:
> On Feb 20, 2008 2:26 AM, MonkeyGirl <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi.
>
> > I know this has been discussed before, but I'm trying to get
> > pagination working with a complex query. The query's got aggregates in
> > it. So far I've got a custom method in my model to run the query and
> > it'd be very easy to adapt it with limit type arguments.
>
> > The hard part is working out how to either get the paginator to use
> > that method instead of findAll, *or* how to retrieve and order by
> > aggregates within paginator's findAll instead. Either way would work,
> > as far as I can tell.
>
> > I've read this thread:
>
> Hey Zoe,
>
> While searching for the very same thing I found a post by Baz in this
> mailing list that talks about how to solve that exact problem. I used
> it myself to implement pagination where I needed a 'group by'.
> Anyhow, to make a long story short, you need to create two methods in
> the model to override the built-in paginate methods.
>
> function paginate($conditions, $fields, $order, $limit, $page = 1,
> $recursive = null) {
> ...
>
> }
>
> function paginateCount($conditions = null, $recursive = 0) {
> ...
>
> }
>
> You need to pass all those parameters so they match findAll() and
> findCount() respectively. For example, here's the ugly hack I did to
> allow me to group results for pagination purposes using 'GROUP BY'
>
> function paginate($conditions, $fields, $order, $limit, $page = 1,
> $recursive = null) {
> $conditions[] ="1 = 1 GROUP BY week, away_team_id, home_team_id";
> $recursive = -1;
> $fields = array('week', 'away_team_id', 'home_team_id');
>
> return $this->findAll($conditions, $fields, $order, $limit,
> $page, $recursive);
> }
>
> function paginateCount($conditions = null, $recursive = 0) {
> $sql = "SELECT DISTINCT ON(week, home_team_id, away_team_id)
> week, home_team_id, away_team_id FROM games";
> $this->recursive = $recursive;
> $results = $this->query($sql);
>
> return count($results);
> }
>
> I'm using Postgres in this case (hence the weird DISTINCT ON stuff).
>
> Hope that helps.
>
> --
> Chris Hartjes
> Internet Loudmouth
> Motto for 2008: "Moving from herding elephants to handling snakes..."
> @TheKeyBoard:http://www.littlehart.net/atthekeyboard
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---