Welcome Guest, Not a member yet? Register   Sign In
Using Pagination Library
#1

Hi all, I want to use the default pagination library coming with CI4 for paginating posts in a page. So, I created the following controller. The result of a query builder is stored in the protected variables $posts. In the index page I have inserted the corresponding code for links creation (<?= $pager->links() ?>). Regardless the number of posts in the page, the pager always creates one link (page). See image below. How I can tell to the pager to create more links (pages)? FYI. I have set $perPage public variable equal to 3 in app/Config/Pager.php.


PHP Code:
<?php

namespace App\Controllers;

class 
Blog extends BaseController
{
    protected $posts;

    public function __construct()
    {
        $db db_connect();
        $query_posts $db->query("SELECT * FROM posts ORDER BY created_at DESC");
        $this->posts $query_posts->getResult();
    }

 public function 
index()
 {
     $data = array(
          'posts'        => $this->posts,
          'pager'        => \Config\Services::pager()
     );

     return view('blog'$data);
    }

Reply


Messages In This Thread
Using Pagination Library - by cifan - 01-03-2022, 11:07 AM
RE: Using Pagination Library - by cifan - 01-04-2022, 12:35 PM
RE: Using Pagination Library - by iRedds - 01-04-2022, 05:29 PM
RE: Using Pagination Library - by BilltheCat - 01-05-2022, 12:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB