2016-09-28 85 views
0

我正在使用數據表內置ajax自定義分頁。如何通過cakephp限制的另一個參數3.2

這裏我需要在限制函數中傳遞2個參數。

我需要一些幫助才能使它成爲可能。我正在使用cakephp 3.2。

以下是我的代碼。

$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; 


This code is in core php , 

I want to convert it into cakephp . 

Below is what i have tried so far. 

$order=$requestData['order'][0]['dir']; //descending ya ascending 
     $id=$columns[$requestData['order'][0]['column']];///order by which column 


$query= $this->Orders->find('all')->where($condition)->limit($requestData['length'])->order(['Orders.'. $id.' '.$order]); 

How can i write this code LIMIT ".$requestData['start']." ,".$requestData['length']." "; 

Using cakephp , 
In limit how to give both the limit as well as the start parameter($requestData['start']). 

最後,這是我的問題的結束。 謝謝任何​​建議將不勝感激。

回答

0

在限制,它支持兩個參數如果傳遞只有一個那麼它是極限參數,和偏移默認

LIMIT 10 //returns first 10 records only 

是0如果傳遞兩個參數然後第一偏移和第二是限制

LIMIT 50, 10 //returns 10 records from 51st record 

在CakePHP的查詢路過偏移,您可以使用offset($start)方法或page($page_number)方法檢查DOC

你的代碼應該是

$query= $this->Orders->find('all')->where($condition)->limit($requestData['length'])->offset($requestData['start'])->order(['Orders.'. $id.' '.$order]); 
+0

哇,它真的工作。 非常感謝,您節省了我的時間。 :) :);) – sradha

+1

WOW ...嚴重嗎? ;) –

+0

是的,我已經在page()中完成了它,但是我需要偏移量。 我瞭解它,並再次感謝你。 ;););):) – sradha

1

存在CakePHP的查詢偏移功能,您可以使用

所以您的查詢變得如下

$查詢= $這個 - >訂單 - >找到(「全部」) - >在哪裏( $ condition) - > offset($ requestData ['start']) - > limit($ requestData ['length']) - > order(['Orders。'。$ id。''。$ order]);

這應該按照要求工作,它與mysql查詢中的啓動相同。