Here is my phalcon controller Action in this function i m using phalcon-datatable
my query is i want to pass dynamic limit argument to this model $jangads::ViewJangads()
Currently I m Passing static limit "limit=>100"
i want it as a dynamic that response to server side processing
public function phalconDatatableLoadAction() {
if ($this->request->isAjax()) {
$this->setJsonResponse();
$request = $this->request;
if (!$request->isPost()) {
$this->invalid_request = true;
return;
}
$type = $request->getPost("id_type");
$from_date = $request->getPost("from_date");
$to_date = $request->getPost("to_date");
$from_carat = $request->getPost("from_carat");
$to_carat = $request->getpost("to_carat");
$machine_id = $request->getpost("machine_id");
$process_id = $request->getPost("process_id");
$client_id = $request->getPost("client_id");
$payment_type = $request->getPost("payment_type");
$condition = "";
if ($from_carat === NULL && $to_carat === NULL && $from_date === NULL && $to_date = NULL && $machine_id === NULL && $process_id === NULL && $client_id === NULL) {
$this->invalid_request = true;
$jangads = ViewJangads::find(array("limit"=>100, "order" => "id DESC")); //Here I want to Pass Dynamic Limit in array
return array('jangads' => $jangads);
}
if ($from_date != NULL && $to_date != NULL) {
$condition = "date_in BETWEEN '$from_date' AND '$to_date'";
}
if ($type != NULL) {
if ($condition != NULL) {
$condition = " and " . $condition;
}
$condition = "type='$type'" . $condition;
}
if ($from_carat != NULL && $to_carat != NULL) {
if ($condition != NULL) {
$condition = " and " . $condition;
}
$condition = "total_weight BETWEEN '$from_carat' and '$to_carat'" . $condition;
}
if ($client_id != NULL) {
if ($condition != NULL) {
$condition = " and " . $condition;
}
$condition = "client_id='$client_id'" . $condition;
}
if ($machine_id != NULL) {
if ($condition != NULL) {
$condition = " and " . $condition;
}
$condition = "find_in_set('$machine_id',machine_id)<>0" . $condition;
}
if ($process_id != NULL) {
if ($condition != NULL) {
$condition = " and " . $condition;
}
$condition = "find_in_set('$process_id',process_id)<>0" . $condition;
}
if ($payment_type != NULL) {
if ($condition != NULL) {
$condition = " and " . $condition;
}
$condition = "payment_type='$payment_type'" . $condition;
}
//$condition = "net_weight BETWEEN '$from_carat' and '$to_weight' and id_party='$id_party' and id_machine='$id_machine' ";
$jangads = ViewJangads ::find(array("conditions" => $condition, "limit"=>100, "order" => "id DESC")); //Here Also I want to pass dynamic limit
$dataTables = new DataTable();
$dataTables->fromResultSet($jangads)->sendResponse();
return array('jangads' => $jangads, 'condition' => $condition);
}
}
if I'm not include limit argument in model then it show mysql
memory issue bcz i have large database and i don't want to increase memory size so help needed and I'm using phalcon framework
Where is your dynamic limit coming from? You can include it in your Ajax request and assign it to $limit as you did with your other variables:
$limit = (int) $request->getPost("limit");
and use it like:
"limit"=> $limit
If your datasets are so big, you can use a mix of LIMIT and OFFSET.
You might also like to explore this feature of Phalcon regarding resultsets:
As storing large query results in memory could consume many resources, resultsets are obtained from the database in chunks of 32 rows - reducing the need to re-execute the request in several cases. (From the docs)