![]() |
Problems with pagination - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Problems with pagination (/showthread.php?tid=76086) |
Problems with pagination - SigveR - 04-13-2020 Hello, 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 string, null given, called in This is my controller at the moment: PHP Code: public function my_listings() { And my model: PHP Code: public function get_users_jobs() { It is working perfectly before trying to mess it up with adding the pagination. I appreciate any help on this. RE: Problems with pagination - wdeda - 04-14-2020 Hi! 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; Model with the research arguments: PHP Code: <?php namespace App\Models; Controller: PHP Code: <?php namespace App\Controllers; RE: Problems with pagination - Jenny425 - 07-02-2020 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: Code: class SubjectCode extends BaseController Then this is my Model Code: function getUsers(){ and here is my View Code: <tbody> Please send help. RE: Problems with pagination - captain-sensible - 07-03-2020 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 = [ 'title'=>'paginate', 'blogs' => $handle->paginate(5), 'pager' => $handle->pager, 'date'=>$this->myDate ]; echo view('header',$data); echo view('listBlogsPaginate',$data); echo view('footer',$data); } //and this is the nitty gritty of the view listBlogsPaginate <?php 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); $pager=$handle->where('category','Mens')->pager; this is about a database where there is a field called "category" |