An alternate to paginator counter showing page in cakephp
An ordinary yet useful piece of hack to the way the cakephp pagination’s pages “showing page” parameter is displayed. As default, we are used to use $paginator->counter() method which gives us a counter string for the paged result set like “Showing page 1 of 3″. But in my latest project task i needed to show results set something like “Showing 1 to 20 of total 46″.
To display the result set like this, i wrote a few lines of code in my view using $paginator object values. Here are the lines of code which i place right under the $paginator->options() call:
$current_page = $this->params['paging'][$paginator->defaultModel()]['page']; //current page $page_count = $this->params['paging'][$paginator->defaultModel()]['pageCount']; //total pages $count = $this->params['paging'][$paginator->defaultModel()]['count']; //total count of records $limit = $this->params['paging'][$paginator->defaultModel()]['options']['limit'];//pages to be shown on a page if($current_page==1) $start_pointer = 1; else $start_pointer = (($current_page-1) * $limit ) + 1; if($current_page==$page_count) $end_pointer = $count; else $end_pointer = $current_page * $limit;
And below is the line which i placed at the top of results table to read it like “Results 1 to 20 of total 46″:
echo "Results " . $start_pointer . " to ".$end_pointer . " of " . $count;
I know this is a cheap hack but it really helped me when i had not much time left to deliver the work. I hope this helps someone else!
Possibly Related posts:
- To check in a smarty template if it was the last page of the page results
Here’s a method to check in a smarty template if it was the last page of page results. {if $listings.current_page gte ($listings.total / $results_per_page)|ceil} True... - Cakephp pagination and custom named arguments handling
Let’s have a look at the scenario first. I have a “contacts” controller, a “display” action in it(controller) and a view “display.ctp” to show results.... - Passed arguments routing and custom ajax pagination url in cakephp
While working in my recent “charity project” i had to list all charities found in a particular region or state. I created a regions_controller and... - A tip on CakePHP find list with related model conditions
You will need to add recursive=>(value) to the $params when you need to get a ‘list’ of table items using related model conditions. Referring to... - How to apply search filters in cakephp ajax pagination
Sometimes we need to filter records via custom query while using ajax pagination in a cakephp application. An easy way to achieve this is to...
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.






Hello,
I was searching for this solution from the last two days. Thanks for your post, it helped me a lot.
Great!