• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] CI4 Pagination don't work fine

#1
Hi to all,

i use CI 4.0.3 and I read CI4 documentation : https://codeigniter.com/user_guide/libra...ation.html

This is my controller:

PHP Code:
<?php namespace App\Controllers;

use App\Models\TenantModel;

class TenantsCtrlComunica extends BaseController
{
    public function __construct(){
        $pager = \Config\Services::pager();
        $this->TenantModel = new TenantModel();
    }
    public function index()
    {
        $data = [
            'tenants'   => $this->TenantModel->paginate(3),
            'pager'     => $this->TenantModel->pager,
        ];
        echo view('tenants_list', $data);
    }


This is my model :

PHP Code:
<?php namespace App\Models;

use 
CodeIgniter\Model;

class 
TenantModel extends Model
{
    protected $table      'tenant_table';
    protected $primaryKey 'id_tenant';
    protected $returnType     'object';
    protected $useSoftDeletes false;
    protected $allowedFields = ['name''enabled''keys''description'];
    protected $useTimestamps true;
    protected $createdField  null;
    protected $updatedField  null;
    protected $deletedField  null;



In my php Page I wrote this:
PHP Code:
<?= $pager->links()?>

BUT, in my web page I watch only an "1" (I attached an image); this is the HTML rendered by previous code:

PHP Code:
...
    <
ul class="pagination">
        <
li class="active"> <a href="http://comunica.local:888/public/tenants?page=1"</a> </li>
    </
ul>
... 


In my database I have 12 records and if I play with pagination's params I see different records.

Where I am wrong? Huh Huh

Many thanks for your help!

Rodrigo
Reply

#2
I solved with this code:

Controller:
PHP Code:
<?php namespace App\Controllers;

use App\Models\TenantModel;

class TenantsCtrlComunica extends BaseController
{
    public function __construct(){
        $this->TenantModel = new TenantModel();
    }

    public function index()
    {
        $currPage = htmlentities($this->request->getGet('page'), ENT_QUOTES, 'UTF-8');            
        $data 
= [
            'currPage'          => (isset($currPage) && $currPage!='') ? $currPage : 0,
            'countAll'          => $this->TenantModel->countAll(),
            'recordsForPage'    => 3,
            'tenants'           => $this->TenantModel->paginate(3),
            'pager'             => $this->TenantModel->pager,
        ];      
        return view
('tenants_list', $data);
    }


Page :

PHP Code:
<?= $pager->makeLinks($currPage$recordsForPage$countAll?>
Reply

#3
Thanks! This line did it for me <?= $pager->makeLinks($currPage, $recordsForPage, $countAll) ?>!
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.