<?php
class AlbumsController extends AppController {
var $name = 'Albums';
function view($id = null) {
$this->Album->id = $id;
$this->set('tracks', $this->Album->read());
}
}
?>
我想知道如何将分页应用于视图功能。我已经解决了以下问题:
var $paginate = array(
'limit' => 8,
'order' => array(
'Album.catalog_no' => 'ASC'
)
);
function index() {
$this->Album->recursive = 0;
$this->set('albums', $this->paginate());
}
但是将它应用到上面的视图函数我有点不知所措。谢谢!
答案 0 :(得分:2)
我假设您需要对某张专辑的所有曲目进行分页:
<?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'));
}
}
?>
如果这不是您要求的,请告诉我,以便我可以解决。 ;)