我在这里使用三个类别。我想在使用分页时从特定类别中获取数据。
我的代码:
public function index( $category_id = null )
{
if (!$this->KnowledgeSolution->KnowledgeCategory->exists( $category_id ))
{
throw new NotFoundException(__('Invalid Knowledge Category'));
}
$KnowledgeCategory = $this->KnowledgeSolution->KnowledgeCategory->read(null,$category_id);
$this->set('KnowledgeCategory', $KnowledgeCategory);
$this->Paginator->settings['contain'] = array('Users', 'KnowledgeReply'=>array('Users') );
$this->set('KnowledgeSolutions', $this->Paginator->paginate());
/*
$this->paginate = array('conditions' => array('Product .title LIKE' => 'a%'),'limit' => 10 );
$data = $this->paginate('Product');
*/
}
答案 0 :(得分:0)
使用以下
public function index( $category_id = null )
{
if (!$this->KnowledgeSolution->KnowledgeCategory->exists( $category_id ))
{
throw new NotFoundException(__('Invalid Knowledge Category'));
}
$KnowledgeCategory = $this->KnowledgeSolution->KnowledgeCategory->read(null,$category_id);
$this->set('KnowledgeCategory',$KnowledgeCategory);
$this->Paginator->settings['contain'] = array('Users','KnowledgeReply'=>array('Users') );
$this->set('KnowledgeSolutions', $this->Paginator->paginate());
$this->Paginator->settings = array('conditions' => array('Product .title LIKE' => 'a%'),'limit' => 10 );
$data = $this->Paginator->paginate('Product');
$this->set(compact('data'));
}