Welcome Guest, Not a member yet? Register   Sign In
How to create pagination on CI4
#1

Hi, I'm having a lot of trouble figuring out how to create pagination on Codeigniter 4.

This is my controller:

PHP Code:
$model = new TestModel();
        
        $data 
= [
            'website' => lang('Auth.website'),
            'title' => lang('Auth.title_home'),

            'auth' => new \App\Libraries\IonAuth(),
            'model' => new TestModel(),

            'validation' => \Config\Services::validation(),
            'session' => \Config\Services::session(),
            'pager' => \Config\Services::pager(),
            
            
'test' => $model->getItem(),
            'categories' => $model->categoryList(),
            'lastComments' => $model->lastComments(5),
        ]; 


This is the model:


PHP Code:
public function getItem($slug false){
        
        
if($slug === false){
            return $this->query('SELECT * FROMa items ORDER BY id DESC')
                ->getResult();
        }

        return $this->asArray()
            ->where(['slug' => $slug])
            ->first();
    


While in the view I recall the pagination. As you can see in the model I create the query to retrieve the results, while in the controller I call the model and pager. But I don't know what else to do, I don't understand how and why to use paginate ()
Reply


Messages In This Thread
How to create pagination on CI4 - by Marcolino92 - 04-08-2020, 10:15 AM
RE: How to create pagination on CI4 - by wdeda - 04-09-2020, 08:38 AM
RE: How to create pagination on CI4 - by wdeda - 04-09-2020, 10:44 AM
RE: How to create pagination on CI4 - by wdeda - 04-09-2020, 01:01 PM
RE: How to create pagination on CI4 - by waleed - 02-18-2021, 03:08 AM
RE: How to create pagination on CI4 - by Mano - 09-17-2021, 05:29 PM
RE: How to create pagination on CI4 - by wdeda - 04-10-2020, 05:09 PM
RE: How to create pagination on CI4 - by InsiteFX - 09-18-2021, 01:07 AM
RE: How to create pagination on CI4 - by danger89 - 02-26-2024, 05:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB