Reputation: 1043
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.
Upvotes: 1
Views: 2282
Reputation: 29141
According to the Cake Book pagination page (HERE), you can set different paging variables for different models (all within the same controller):
In fact, you can define more than one set of pagination defaults in the controller, you just name the pieces of the array after the model you wish to configure:
class RecipesController extends AppController {
var $paginate = array(
'Recipe' => array (...),
'Author' => array (...)
);
}
Upvotes: 1
Reputation: 2580
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!
Upvotes: 1