Problems with pagination |
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" |
Messages In This Thread |
Problems with pagination - by SigveR - 04-13-2020, 04:06 PM
RE: Problems with pagination - by wdeda - 04-14-2020, 04:34 AM
RE: Problems with pagination - by Jenny425 - 07-02-2020, 08:58 PM
RE: Problems with pagination - by captain-sensible - 07-03-2020, 10:27 AM
|