Search code examples
phpcodeignitercodeigniter-4

How to know total pages of pagination in codeigniter 4


I am using codeigniter 4, I created pagination in view and its display the results fine. But I want to know total page for this results. The view code for pagination is -

<?php if ($pager) :?>
   <?php $pagi_path=getenv('pagi_path').'search'; ?>
   <?php $pager->setPath($pagi_path); ?>
   <?= $pager->links() ?>
<?php endif ?>

Solution

  • $pager->getPageCount() - gives you total count of pages

    Class is located in system/Pager/Pager.php , you can look it's methods for even more 'extras'