簡體   English   中英

如何在cakephp 3.2的限制中傳遞另一個參數

[英]How to pass another parameter in limit of cakephp 3.2

我正在使用數據表內置的ajax自定義分頁。

在這里,我需要在極限函數中傳遞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']).

最終,這就是我問題的結尾。 謝謝您的任何建議,將不勝感激。

cakephp查詢中有一個偏移量函數,您可以使用

所以你的查詢如下

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

這應該按要求工作,與在mysql查詢中啟動相同。

在Limit中,如果僅傳遞一個參數,則它支持兩個參數,則它是limit參數,默認情況下,offset為0

LIMIT 10 //returns first 10 records only

如果傳遞兩個參數,則第一個為偏移量,第二個為極限

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

page($page_number)在CakePHP查詢中傳遞偏移量,可以使用offset($start)方法或page($page_number)方法檢查DOC

您的代碼應為

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM