In CakePHP pagination is provided by a Component defined in the controller for making paginated queries much easier.
PaginatorHelper View is used for generating pagination links & buttons in a simpler way.
Setting up the Query:
Let us take a controller with name Posts,so the query will go as:
class PostsController extends AppController {
public $components = array('Paginator'); //Using Paginator Component
public $paginate = array(
'fields' => array('Post.id', 'Post.created'),
'limit' => 25,
'order' => array(
'Post.title' => 'asc'
)
);
}
The pagination query uses $paginate controller variable by default.These conditions,acts as the basis of the pagination queries applied.
//Function which uses Paginator
public function_list(recipes) {
$this->Paginator->settings = $this->paginate;
// similar to findAll(), but fetches paged results
$data = $this->Paginator->paginate('Recipe');
$this->set('data', $data);
}
One can set conditions and other pagination array settings inside your action.Enjoy guys!!!
0 Comment(s)