Welcome Guest, Not a member yet? Register   Sign In
Pagination using ajax in codeigniter 4
#6

(This post was last modified: 06-08-2021, 01:10 AM by InsiteFX.)

You can do it, it has methods for getting that data see the below blog method $data
PHP Code:
/**
 * -------------------------------------------------------------------
 * posts ()
 * -------------------------------------------------------------------
 *
 *
 */
 
public function posts()
 {
 
$pager Services::pager();

 
$posts      = new PostModel($this->request);
 
$categories = new CategoryModel();

 
$data = [
 
'posts'      => $posts->getLivePosts()->paginate(3'group1'),
 
'pager'      => $posts->pager,
 
'currentPage' => $posts->pager->getCurrentPage('group1'),
 
'totalPages'  => $posts->pager->getPageCount('group1'),
 
'categories'  => $categories->getTopCategories(),
 
'title'      => 'Blog Home',
 
'pageHeading' => 'Blog',
 
'subHeading'  => 'Home',
 
'typography'  => Services::typography(),
 ];

 
// Make all variables global to all views. (Empty PHP File)
 
echo view('Insitefx\Blog\Views\view_data'$data);
 echo 
view('Insitefx\Blog\Views\posts\index');
 } 
I use custom Bootstrap Pagers for this which you can find the code in the forums here.

Here is the partial view code I use layouts.

PHP Code:
<!-- Pagination -->
<
div class="pagination justify-content-center mb-4">
 <?
php if ( ! empty($pager)) :
    //echo $pager->simpleLinks('group1', 'bs_simple');
    echo $pager->links('group1''bs_full');
 endif 
?>

 <!-- Bootstrap 4.5.2 code to show page 1 of 4 total pages using a button. -->
 <div class="btn-group pagination justify-content-center mb-4" role="group" aria-label="pager counts">
 &nbsp;&nbsp;&nbsp;
 <button type="button" class="btn btn-light"><?= 'Page '.$currentPage.' of '.$totalPages?></button>
 </div>
</div> 
hope that helps.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: Pagination using ajax in codeigniter 4 - by InsiteFX - 06-08-2021, 01:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB