Welcome Guest, Not a member yet? Register   Sign In
Pagination with Custom model
#8

(This post was last modified: 01-07-2021, 02:34 AM by AndreaL.)

(01-04-2021, 05:33 AM)includebeer Wrote: What do you mean by custom model?

I have examples for pagination in these 2 articles:
https://includebeer.com/en/blog/how-to-b...r-4-part-4
https://includebeer.com/en/blog/how-to-b...r-4-part-5

Hi, if you refer to my question I have posted the code.
By "custom model" I mean that I am not extending codeigniter's model but I have built a model of my own.
If I extend Codeigniter's model I have no problem with pagination. But with the custom model it does not work.
On the code I have posted, how would you add pagination?

(01-04-2021, 10:04 AM)Mostafa Khudair Wrote:
(12-31-2020, 03:59 AM)Here we go. Wrote: CONTROLLER:
PHP Code:
<?php

namespace App\Controllers;

use 
App\Models\CustomModel;

class 
Annunci extends BaseController
{

  public function index()
  {
     $model = new CustomModel();
     $data['annunci'] = $model->annunci();
     $data['page']    $model->pager;

     return view('cet'$data);
  }


MODEL:

PHP Code:
protected $table 'annunci';

public function 
annunci()
{
  return $this->orderBy('data''DESC')->paginate();


VIEW:
PHP Code:
<?php foreach ($annunci as $value): ?>
  <span><?= $value->id ?></span>
<?php endforeach ?>

It's very recommended to read userguide

Hi,
I believe your answer assumes I am extending Codeigniter's model, am I right?
If so, I am not doing that. Mine is a custom model
Reply


Messages In This Thread
Pagination with Custom model - by AndreaL - 12-31-2020, 03:59 AM
RE: Pagination with Custom model - by InsiteFX - 12-31-2020, 12:27 PM
RE: Pagination with Custom model - by AndreaL - 01-04-2021, 03:03 AM
RE: Pagination with Custom model - by seunex - 01-04-2021, 04:01 AM
RE: Pagination with Custom model - by includebeer - 01-04-2021, 05:33 AM
RE: Pagination with Custom model - by AndreaL - 01-07-2021, 02:31 AM
RE: Pagination with Custom model - by rmcdahal - 01-04-2021, 06:29 AM
RE: Pagination with Custom model - by includebeer - 01-07-2021, 08:19 AM
RE: Pagination with Custom model - by AndreaL - 02-09-2021, 03:41 AM
RE: Pagination with Custom model - by MuhAnhar - 01-12-2021, 06:06 AM
RE: Pagination with Custom model - by includebeer - 01-12-2021, 03:46 PM
RE: Pagination with Custom model - by InsiteFX - 02-09-2021, 07:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB