tags:

views:

210

answers:

1
<?php
class AlbumsController extends AppController {
    var $name = 'Albums';

    function view($id = null) {
     $this->Album->id = $id;
     $this->set('tracks', $this->Album->read());
    }
}
?>

I'm wondering how I would apply paginating to the view function. I've got it worked out 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'm at a bit of a loss. Thanks!

+2  A: 

I assume you need to paginate all the tracks of a certain 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 I can fix it. ;)

dr Hannibal Lecter
Wonderful, thanks heaps! Only one thing to change - "var $paginate = = array". Just need to remove the second equals sign. Other than that it works perfectly.
There we go.. :)
dr Hannibal Lecter