CodeIgniter Forums
Hide pager when only 1 page of results - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Hide pager when only 1 page of results (/showthread.php?tid=87296)



Hide pager when only 1 page of results - JoosepK - 04-04-2023

Hello! 

I am creating my first project with CodeIgniter 4.
Could you please explain how i can hide pager / pagination links in view when there are results for only one page?
I know some ways but i think CodeIgniter has some built in solution for that..
I use the pager class like this:
PHP Code:
$clients $this->model->orderBy('id')->paginate(20); 

Thank you for your help


RE: Hide pager when only 1 page of results - digitalarts - 04-12-2023

This is what I use:
PHP Code:
if ( $pager->getPageCount() > ) {
     echo $pager->links();
 } 



RE: Hide pager when only 1 page of results - CarmosKarrvx - 04-19-2023

CodeIgniter 4 provides a built-in solution for hiding pagination links when there are results for only one page. You can use the hasMore method of the Pager class to check if there are more pages available. If there is only one page, then this method will return false. You can use this to conditionally display the pagination links in your view.

Here's an example code snippet that demonstrates how to do this:

<?php if ($clients->hasMore()): ?>
<div class="pagination">
<?= $clients->links() ?>
</div>
<?php endif; ?>
In this example, we're using the hasMore method to check if there are more pages available. If there are, then we display the pagination links using the links method of the Pager class. If there is only one page, then the pagination links will not be displayed.


RE: Hide pager when only 1 page of results - JoosepK - 10-05-2023

(04-19-2023, 03:54 AM)CarmosKarrvx Wrote: CodeIgniter 4 provides a built-in solution for hiding pagination links when there are results for only one page. You can use the hasMore method of the Pager class to check if there are more pages available. If there is only one page, then this method will return false. You can use this to conditionally display the pagination links in your view.

Here's an example code snippet that demonstrates how to do this:

<?php if ($clients->hasMore()): ?>
    <div class="pagination">
        <?= $clients->links() ?>
    </div>
<?php endif; ?>
In this example, we're using the hasMore method to check if there are more pages available. If there are, then we display the pagination links using the links method of the Pager class. If there is only one page, then the pagination links will not be displayed.

Thank you!

(04-12-2023, 01:44 PM)digitalarts Wrote: This is what I use:
PHP Code:
if ( $pager->getPageCount() > ) {
     echo $pager->links();
 } 
Thank you!