kunal kunal - 1 year ago 80
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')); ?>

Answer Source

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}');    
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download