gpt4 book ai didi

cakephp - 如何在 CakePHP 中为特定功能自定义分页?

转载 作者:行者123 更新时间:2023-12-01 05:47:17 25 4
gpt4 key购买 nike

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

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

我想知道如何将分页应用于 View 函数。我已经解决了以下问题:
var $paginate = array(
'limit' => 8,
'order' => array(
'Album.catalog_no' => 'ASC'
)
);

function index() {
$this->Album->recursive = 0;
$this->set('albums', $this->paginate());
}

但是将它应用到上面的 View 函数我有点不知所措。谢谢!

最佳答案

我假设您需要对某个专辑的所有轨道进行分页:

<?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'));
}
}
?>

如果这不是您问的问题,请告诉我,以便我可以解决。 ;)

关于cakephp - 如何在 CakePHP 中为特定功能自定义分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1027946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com