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
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.