Use Set::merge() to modify the $paginate property

Let’s say you have a Posts controller, where you’ll need to paginate some posts in various actions.
You might have some “generic settings” as the manual recommends in your $paginate variable similar to this:

var $paginate = array('Post'=>array('limit'=>10, 'order'=>array('Post.modified DESC')));

Now, the above setting is probably going to work well for all of your actions where pagination is required. However, in some actions you need to also add a ‘contain’ key and maybe some ‘conditions’…

We can easily merge our main “setting” and any other desired keys we’d normally pass to $paginate, by using Set::merge()

Let’s say this is our extendedView() action of the Posts controller:

$this->paginate = Set::merge($this->paginate,
     'contain'=>array('Thread'=>array('Professor', 'Student'))

Related Posts