June 30, 2014

June 30, 2014
In this article, we are going to discuss about How to set conditions in CakePHP pagination. CakePHP is an open source web application framework. It follows the Model-View-Controller (MVC) approach and is written in PHP, modeled after the concepts of Ruby on Rails, and distributed under the MIT License. CakePHP uses well-known software engineering concepts and software design patterns, as Convention over configuration, Model-View-Controller, Active Record, Association Data Mapping, and Front Controller.

Pagination is the process of dividing (content) into discrete pages, either electronic pages or printed pages. To get custom result in CakePHP pagination, we can set conditions. To set condition in pagination we can pass it by 'conditions' tag.

Example of set conditions in pagination:

//Ready the conditions array()
$conditions = array();
if(isset($districtID)){
          $conditions[] = array('Subscriberpost.district_id' => $districtID);
}
if(isset($categoryID)){
          $conditions[] = array('Subscriberpost.service_category_id' => $categoryID);
}
$this->Subscriberpost->recursive = 1;
//Set the conditions for pagination
$this->paginate = array('conditions' => $conditions);
//Pass the pagination value to view file
$this->set('subscriberposts', $this->paginate()); 

0 comments:

Post a Comment