• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with pagination


I have been trying to figure out how to set up pagination. I've read the documentation several times, but can't understand why it is not working. It should be simple from my understanding.

This is the error I'm receiving

PHP Code:
Argument 1 passed to CodeIgniter\Database\BaseResult::getResult() must be of the type stringnull givencalled in 

This is my controller at the moment:

PHP Code:
  public function my_listings() {
        $jobs = new \App\Models\Jobs();

        if (!$this->ionAuth->loggedIn())
            return redirect()->to('/logg-inn');

        $this->meta =
                'site_name' => 'Lynt',
                'title' => 'Innstillinger',
                'description' => 'test',

        $data = ([
            'meta' => $this->meta,
            'uri' => $this->uri,
            'session' => $this->session,
            'ionAuth' => $this->ionAuth,
            'validation' => $this->validator,
            'jobs' => $jobs->paginate(10)->get_users_jobs(),
            'pager' => $jobs->pager()->get_users_jobs(),


        echo view("moonlanding/header_moonlanding"$data);
        echo view("moonlanding/userhome/my_listings"$data);
        echo view("moonlanding/footer_moonlanding"$data);


And my model:

PHP Code:
    public function get_users_jobs() {
        $this->categories = new \App\Models\Categories();
        $builder $this->db->table('jobs');
                ->join('users''users.id = jobs.jobs_u_id')
                ->join('categories''category_id = jobs.jobs_category')
                ->where('jobs_u_id ='$this->current_user->id);
        $query $builder->get();
        if ($builder->countAllResults() > 0)
            return $query;

        } else {
            return false;

It is working perfectly before trying to mess it up with adding the pagination. I appreciate any help on this.

You will probably have to use 2 models.
In my case, for example, I have a record where the four main genres are listed, when I click on one of the genres, all the albums I have of that genre are listed.

Model where I collect the DB data:
PHP Code:
<?php namespace App\Models;

// 20200408

use CodeIgniter\Model;

AlbunsDataModel extends Model
protected $table 'albuns';
    protected $allowedFields = ['id''title''ano'];
    protected $returnType 'object';    

Model with the research arguments:
PHP Code:
<?php namespace App\Models;


use CodeIgniter\Model;

AlbunsListModel extends Model
    public function getGenre1()
        $request = \Config\Services::request();
        $uri $request->uri;
        $id $uri->getSegment(3);
        $db db_connect();
        $query $db->table('albuns')

        foreach($query->getResult() as $row);
return $row->style1;

    public function numGenre1()
        $request = \Config\Services::request();
        $uri $request->uri;
        $id $uri->getSegment(3);
        $db db_connect();
        $query $db->table('albuns')

        foreach($query->getResult() as $row);
        $data $numgnr1->countAllResults();
return $data;
//and so on... 

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

    class Albumlists extends Controller {    
public function genre1()
= new AlbunsDataModel();
        $listModel = new AlbunsListModel();

        $style $listModel->getGenre1();
= [
            'genre1' => $dataModel->orderBy('player_id''ano''title''asc')
            'pager' => $dataModel->pager,
            'total' => $listModel->numGenre1(),
            'genre' => $listModel->getGenre1()

      $header = array ( 
'icon' => 'favicon'
'css' => 'albumlists',
'title' => $genre' records - wdeda',
'search' => '/ci4/search/allmedia/',
'placeholder' => 'Pesquisar'

//and so on...

I also have problem with pagination. I'm new to codeigniter and just started learning last 2 weeks and I'm stuck on how to make the pagination work on my project. I have also read the documentation and still can't understand how it works for paginating a query where I joined a table with other tables. I also tried paginating first the main table but how could i print out the data of a specific user from other tables? Please can someone help me.

This is my Controller:
class SubjectCode extends BaseController

    public function index()
    { ...}

    public function users()
            $db = db_connect();
            $model = new CustomModel($db);

            $data = [
                'users' => $model->getUsers()->get()->getResultArray(), //I got an error if I paginate this line: Call to a member function paginate() on array
                'pager' => $model->pager
            return view('/subj_students', $data);

Then this is my Model
    function getUsers(){
        $builder =  $this->db->table('users')
                        ->orderBy('users.usr_lname', 'ASC')
                        ->join('classes', 'usrs.class_id = classes.class_id')
                        ->join('subjectCode', 'users.usr_id = subjectCode.subjectCode_id');
        return $builder;


and here is my View
              <?php if($students): ?>
                  <?php $i = 1; ?>
                      <?php foreach($users as $student): ?>
                           <td align="center"><?php echo $i; ?></td>
                         <td><?php echo $student['usr_lname'].", ".$student['usr_fname']; ?></td>
                         <td><?php echo $student['usr_id_no']; ?></td>
                         <td><?php echo $student['course'].$student['year'].$student['section']; ?></td>
                         <td><?php echo $student['subjectCode_name']; ?></td>
                     <?php $i++;
                     endforeach; ?>
                 <?php else: ?>
                     <td colspan='5'>No record found.</td>
             <?php endif; ?>
         <div class="row">
          <div class="col-md-12">
            <div class="row">
              <?php if ($pager) :?>
              <?php $pagi_path= '/subj/subj_students'; ?>
              <?php $pager->setPath($pagi_path); ?>
              <?= $pager->links() ?>
              <?php endif ?>       

Please send help.

maybe i'm old school but if i can't get something to work i start first with minimalist code; when that works i build on it.

this is my blog model :

<?php namespace App\Andy;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Model;

class BlogModel extends Model


protected $table = 'blog';
protected $primaryKey = 'Id';
protected $allowedFields = ['title','article','image','slug','date'];
protected $limit;
protected $offset;
protected $Id;
protected $title;
protected $article;
protected $slug;

this is my controller
public function doPaginate()
$handle = new BlogModel();
$data = [
'blogs' => $handle->paginate(5),
'pager' => $handle->pager,

echo view('header',$data);
echo view('listBlogsPaginate',$data);
echo view('footer',$data);


//and this is the nitty gritty of the view listBlogsPaginate


foreach($blogs as $blogy)

echo "<h11><a href = blogArticle/" . $blogy['slug'] . "> ". $blogy['slug'] ." </a> </h11> <br> ";


so this just lists the blogs i have , i limit blogs for each page to 5

then the bit showing links on view is just :
<h3 class ="links"><?= $pager->links() ?></h3>

//so basically paginate is a method that does a lot of work behind the scene . My advice when working with a new concept strip everything back to focus on the new concept . Once you get it working then build on it . My understanding is that basically paginate gets the total records in a database and splits it up as per :

$handle->paginate(5); // groups of five listings

//the pager in a view takes you to the next group

and if you loo at this line : 'blogs' => $handle->paginate(5),

'blogs' is an array holding the field data, which i access using a standard " foreach

...as "

where you want to filter stuff i've done this :

$result= $handle->where('category','Mens')->paginate(5);

this is about a database where there is a field called "category"

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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