Welcome Guest, Not a member yet? Register   Sign In
Success to CI4 Last Version
#13
Lightbulb 

In your Controller
PHP Code:
$pager = \Config\Services::pager();
 
$model = new TestModel();
 
 
$this->data['root'] = [
            'data'  => $model->paginate(10),
            'pager' => $model->pager
        
]; 

In your Model, Overrite system function paginate
PHP Code:
public function paginate(int $perPage nullstring $group 'default'int $page nullint $segment 0)
 {
 
$this->table 'lott_index';
 
$pager = \Config\Services::pager(nullnullfalse);

 if (
$segment)
 {
 
$pager->setSegment($segment);
 }

 
$page $page >= $page $pager->getCurrentPage($group);

 
// Get Total Records - Your query here to get Total Records - example below
 
$sql  "SELECT COUNT(id) AS total FROM lott_index LIMIT 1";
 
$query $this->db->query($sql);
 if (
count($query->getResult()) == 1) {
 
$row  $query->getRow();
 
$total intval($row->total);
 } else {
 
$total 0;
 }

 
// Store it in the Pager library so it can be paginated in the views.
 
$this->pager $pager->store($group$page$perPage$total$segment);
 
$perPage    $this->pager->getPerPage($group);
 
$offset      = ($page 1) * $perPage;

 
// Your query here to get Data For Per Page, example below
 
$query  " SELECT *";
 
$query .= " FROM lott_index";
 
$query .= " ORDER BY dates";
 
$query .= " LIMIT ".$offset.",".$perPage;
 
$query  $this->db->query($query);

 return 
$query;
 } 

This working fine for custom QUERY...

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply


Messages In This Thread
Success to CI4 Last Version - by nc03061981 - 09-21-2020, 01:14 AM
RE: Success to CI4 Last Version - by nc03061981 - 09-21-2020, 02:15 AM
RE: Success to CI4 Last Version - by MGatner - 09-22-2020, 03:58 AM
RE: Success to CI4 Last Version - by nc03061981 - 09-22-2020, 05:43 AM
RE: Success to CI4 Last Version - by nc03061981 - 09-25-2020, 10:17 PM
RE: Success to CI4 Last Version - by nc03061981 - 09-26-2020, 07:27 AM
RE: Success to CI4 Last Version - by nc03061981 - 09-28-2020, 05:17 AM
RE: Success to CI4 Last Version - by nc03061981 - 09-29-2020, 06:01 PM
RE: Success to CI4 Last Version - by nc03061981 - 09-30-2020, 08:43 PM
RE: Success to CI4 Last Version - by someone - 09-30-2020, 11:37 PM
RE: Success to CI4 Last Version - by nc03061981 - 10-01-2020, 01:39 AM
RE: Success to CI4 Last Version - by nc03061981 - 10-01-2020, 05:51 PM
RE: Success to CI4 Last Version - by nc03061981 - 10-02-2020, 07:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB