Welcome Guest, Not a member yet? Register   Sign In
Pagination don't work
#5

(This post was last modified: 02-18-2021, 08:03 PM by wdeda.)

Simple things work better.
Less is more.
Of course, simple sugestions.
Model:
PHP Code:
<?php<?php
namespace App\Models;

use 
CodeIgniter\Model;

class 
UserModel extends Model
{
    protected $table  'users';
    protected $primaryKey 'id';
    
    
public function numUsers()
    {
    $db $this->db;
    $count $db->table('users');
    return $count->countAllResults();
    }
    


Controller:
PHP Code:
<?php namespace App\Controllers;
    
    
use CodeIgniter\Controller;
    use App\Models\UserModel;

    class Users extends Controller {

    public function index() {
    
    $model 
= new UserModel();
    
    $data 
= [    
    
'users' =>$model->select('id_user, name_user')
    ->orderBy('id_user''asc')
    ->pagination(10),
    'pager' => $model->pager,
    'total' => $model->numUsers;  
    
];
    
    
// Standardization I use on the website
    $header = [
    'glbstrap'  => 'bootstrap'// general css
    'css'       => 'namelists'// specific css for certain pages
    'title'     => 'Simple example of pagination - dimonisse' // page title
    ];
    
    
echo view('templates/header'$header);
    echo view('users/user'$data);
    echo view('templates/footer');    
        
    
}



A portion of the View(pager)
PHP Code:
<div class="users-pages-index">
  <?php if ($total 10) { ?>
  <?php if ($pager) : ?>
  <?php $pagi_path '/user/namelists/users' ?>
  <?php $pager->setPath($pagi_path); ?>
  <?= $pager->links() ?>
  <?php endif ?>
  <?php ?>
Reply


Messages In This Thread
Pagination don't work - by dimonisse - 11-15-2019, 02:18 AM
RE: Pagination don't work - by pi26 - 02-18-2021, 10:55 AM
RE: Pagination don't work - by InsiteFX - 02-18-2021, 12:22 PM
RE: Pagination don't work - by wdeda - 02-18-2021, 02:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB