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!