kunal kunal - 1 month ago 4x
PHP Question

Cakephp show number of items in page

I am using cakephp framework . I have 10 items in one page and 5 items in 2nd page. The items are coming dynamically fetched from database. I want to show the number of items in per page

For Example:

1st page contains 10 items I want output : 1 of 10

2nd page contains 5 items

I want output : 11 of 15

Can anyone tell me what will i do in coding i am using pagination in that case.

My code is as follow:

<?php echo $this->Paginator->prev('« Previous', null, null, array('class' => 'disabled')); ?>
<?php echo $this->Paginator->numbers(); ?>
<?php echo $this->Paginator->next('Next »', null, null, array('class' => 'disabled')); ?>


You should have mentioned the version you're using.

For CakePHP 3, refer to Creating a page counter in CakePHP 3.x

echo $this->Paginator->counter('{{start}} of {{end}}');  // 1 of 10 (for page 1)

For CakePHP 2, refer to Creating a page counter in CakePHP 2.x

echo $this->Paginator->counter('{:start} of {:end}');