2014-09-24 97 views
0

HI我想实现分页我发现所有的查询结果,其中我收到来自不同的表与用户的所有信息分页与找到的所有结果

我发现所有查询的CakePHP:

$result = $this->User->find('all',array(
       'order' => array('User.id' => 'DESC'), 
       'conditions' => $filters 
     )); 

我的分页查询:

$this->paginate['User'] = array(
      'limit' => 20, 
      'order' => array('User.id' => 'DESC') 
         ); 

在查询$过滤结果的条件。

所以我想合并两个查询&获取所有用户相关的数据,但每页只有20个用户。

我试过但无法正确合并这两个查询。

谢谢..

+0

很长一段时间,我已经在蛋糕php的纯分页工作;我总是用数据表jquery工作,所以我不确定你用于分页的语法我有一些疑问plz你可以看看这个链接http://technet.weblineindia.com/web/example-pagination -in-cakephp/ – 2014-09-24 15:02:07

+0

谢谢@ maysaghira的回复,但它没有帮助我。 – Ankit 2014-09-24 15:45:30

+0

查看http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#query-setup的最后一项功能,您可以在分页设置中添加条件 – Abhishek 2014-09-24 16:33:04

回答

0

的PaginatorComponent使用查找查询,其基于请求参数的限制,所以它可以做任何事情经常发现调用即可。

public function index() { 
    // add any filters you want here 
    $filters = array('RelatedModel.field' => 'value'); 
    $this->Paginator->settings['conditions'] = $filters; 
    $this->Paginator->settings['contain'] = array('RelatedModel'); 
    $this->set('users', $this->Paginator->paginate('User')); 
} 

这里我们包含RelatedModel,因此您可以搜索(假设它是一个简单的连接)并包含RelatedModel数据。