2015-01-20 53 views
1

我正在用AngularJS &申请CakePHP。CakePHP分页顺序不起作用

我在Cake中有一个Web服务,它可能会返回有序的数据,但它没有这样做,它返回的数据来自数据库。

这是我的代码部分:

 $this->Paginator->settings = array('limit' => 20, 'page' => $this->request->data['page']+1, 'recursive' => -1); 
    $data = $this->Paginator->paginate('Country', $conditions, $order); 

人有一个想法?

回答

0

这里的分页程序的PAGINATE组件的签名(见http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#custom-query-pagination):

public function paginate(Model $model, $conditions, $fields, $order, $limit, 
    $page = 1, $recursive = null, $extra = array()) 

你应该通过第二个参数是字段,不是为了。

但是,您也可以在设置数组中定义顺序,就像使用查找条件一样。

+0

是的,你说得对,我解决我的代码,但它不工作: $这个 - > Paginator->设置=阵列( '限制'=> 20' page'=> $ this-> request-> data ['page'] + 1,'recursive'=> -1); $ data = $ this-> Paginator-> paginate('Country',$ conditions,array(),$ order); – 2015-01-20 20:57:46

0

试试这个

$this->paginate = array(
     'limit' => 20, 
     'conditions'=>$conditions, 
     'order' => $order 
     ); 
$data = $this->paginate('Country'); 
+0

感谢您的评论,但它不起作用,我得到了相同的输出... :-( – 2015-01-29 15:42:35

+0

你能告诉我什么是'$ order'变量吗? – Sadikhasan 2015-01-29 15:45:23

+0

我通过POST收到排序条件(ifset($ this-> request-> data ['SORTCountry_name'])) { if($ this-> request-> data ['SORTCountry_name']) { array_push($秩序, “Country.name DESC”);} 其他 { array_push($秩序, “Country.name ASC”);} } 我 通过JSON发送回$秩序,具有“国家.name DESC“作为值 – 2015-01-29 15:58:06