CakePHP 1.2 Paginate associated model
26/04/2008
Ok this took a while for me to figure out. But it is possible to override the default pagination function in CakePHP so you paginate a different model, i paginated all related articles on a tag with this example.
- <?php
- public function paginate($conditions = null, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) {
- $tag = $conditions['tag'];
- }
- $this->hasAndBelongsToMany['Article'] = am(
- $this->hasAndBelongsToMany['Article'],
- );
- $result = $this->findByName($tag);
- } else {
- $result = $this->findAll();
- }
- return $result;
- }
- public function paginateCount($conditions = null) {
- $tag = $conditions['tag'];
- $tmp = $this->hasAndBelongsToMany['Article'];
- $this->hasAndBelongsToMany['Article'] = $tmp;
- }
- $tags = $this->findByName($tag);
- } else {
- $tags = $this->findAll();
- }
- return $amount;
- }
- ?>