我有一个模型Categories愿望与Channels模型(belongsToMany)相关联。 在视图类别我有很多相关频道,我想要分页。 表格频道不具有category_id我使用表格category_channels进行关系。
如果我使用此代码:
$category = $this->Categories->get($id, ['contain' => ['Users', 'Chanels']]);
$this->paginate = [
'contain' => ['Chanels', 'Users'],
'sortWhitelist' => [
'Chanels.title'
]
];
$this->set('category', $this->paginate($category));
我有错误: 错误:调用未定义的方法App \ Model \ Entity \ Category :: alias()
我尝试过其他代码:
$query = $this->Categories->find('all')
->where(['Categories.id' => $id])
->contain(['Users', 'Chanels' => function($q) {
return $q
->order('created ASC')
->limit(5);
}]);
$category = $this->paginate($query);
$this->set(compact('category'));
$this->set('_serialize', ['category']);
它的工作我在相关频道有5个频道,但分页不起作用! 如何对频道进行分页? 谢谢你的帮助!