How to set up pagination for a specific function in CakePHP?

<?php class AlbumsController extends AppController { var $name = 'Albums'; function view($id = null) { $this->Album->id = $id; $this->set('tracks', $this->Album->read()); } } ?> 

I am wondering how I would apply pagination to a presentation function. I did it for things like:

 var $paginate = array( 'limit' => 8, 'order' => array( 'Album.catalog_no' => 'ASC' ) ); function index() { $this->Album->recursive = 0; $this->set('albums', $this->paginate()); } 

But applying it to the above view function, I lose a little. Thanks!

+4
source share
1 answer

I assume that you need to break all the tracks of a particular album:

 <?php class AlbumsController extends AppController { var $name = 'Albums'; var $paginate = array ( 'Track' => array ( 'limit' => 8, 'recursive' => -1, // optional, see what you get when you remove it 'order' => array('Track.yourOrderField' => 'ASC') /* other conditions... */ ) ); function view($id = null) { $this->paginate['Track']['conditions'] = array('Track.album_id' => $id); $this->set('tracks', $this->paginate('Track')); } } ?> 

If this is not what you asked, let me know so that I can fix it. ;)

+2
source

Source: https://habr.com/ru/post/1286580/


All Articles