Welcome Guest, Not a member yet? Register   Sign In
Hide pager when only 1 page of results
#1

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
Reply
#2

(This post was last modified: 04-12-2023, 01:44 PM by digitalarts.)

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

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.
Reply
#4

(This post was last modified: 10-05-2023, 02:06 PM by JoosepK.)

(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!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB