![]() |
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
This is what I use:
PHP Code: if ( $pager->getPageCount() > 1 ) {
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. (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. Thank you! (04-12-2023, 01:44 PM)digitalarts Wrote: This is what I use:Thank you! |
Welcome Guest, Not a member yet? Register Sign In |