PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 16, 2022

[FIXED] Multiple paginations in one controller

 January 16, 2022     cakephp, cakephp-1.3, controller, pagination     No comments   

Issue

Is there a possibility to use more than one $paginate variable in the same controller?

My problem is that I have an hasAndBelongsToMany-Relation between Links and Tags. I have customized the pagination options so that it works with the habtm:

public $paginate = array(
'limit' => 25,
'joins' => array(
    array(
        'table' => 'links_tags',
        'type' => 'inner',
        'alias' => 'LinkTag',
        'conditions' => array(
            'Link.id = LinkTag.link_id'
        )
    )
));

It works fine, but there is another action which should be also paginated. In this action there is no tag available so every links is shown as often as there is an entry in the links_tags table for that link.

The easiest way to solve this problem is to use a second $paginate variable, but I did not found a solution how can I do that.


Solution

You can customise your paginate methods in various ways after the $paginate variable has been set, as per examples such as this one in the Cake Cookbook:

function list_recipes() {
    $this->paginate = array(
        'conditions' => array('Recipe.title LIKE' => 'a%'),
        'limit' => 10
    );
    $data = $this->paginate('Recipe');
    $this->set(compact('data'));
);

I haven't tested it out, but I would have thought you could put stuff like your join, which needs to vary from one action to another, in the $this->paginate call, rather than the $paginate variable. Hmm, I'll have to see if this works - could be very useful for me to know how to do this kind of thing, for later use!



Answered By - thesunneversets
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing