php - How to paginate with codeigniter 3.0.1 -
i trying create pagination using codeigniter. displays links fine, when click links shows 404 error. how solve this?
controller example.php
class example extends ci_controller { public function __construct() { parent::__construct(); $this->load->model('donor_model'); $this->load->library('pagination'); $this->load->helper('url'); $this->load->library('form_validation'); } public function get_details() { $config['base_url'] = base_url('info'); $config['total_rows'] = $this->donor_model->count(); $config['per_page'] = 10; $config['uri_segment'] = 3; $choice = $config['total_rows']/$config['per_page']; $config['num_links'] = round($choice); $this->pagination->initialize($config); $page =($this->uri->segment(3)) ? $this->uri->segment(3) : 0; $data['data'] = $this->donor_model->get_data([], [],$config['per_page'],$page); $data['links'] = $this->pagination->create_links(); $this->load->view('admin/info',$data); } }
model (example_model.php)
example_model
class extends my_model class
:
class donor_model extends my_model { protected $table = 'donors'; public function __construct() { //call my_model construtor parent::__construct(); } public function get_data($where, $fields,$limit, $start) { return $this->get($where,$fields , $limit, $start); } public function count_data() { return $this->count(); }
model (my_model.php)
class my_model extends ci_model { protected $table = null; // protected $table_fields = []; // protected $fillable = []; // protected $protected = []; protected $primary_key = 'id'; function __construct() { parent::__construct(); $this->load->database(); } /** * return table contents * @param array $where ,$fields, $limit * @return array *defualt $sortorder = dsc */ // public function get(array $where = null, $limit = 1000, $sortorder = 'dsc') public function get(array $where = null, array $fields = null, $limit = null, $start = null) { $query = null; // return records fields table if($fields == null , $where == null){ $this->db->limit($limit, $start); $query = $this->db->get($this->table); if ($query->num_rows() > 0 ) { return $query->result(); } else return false; } // rteurn records fields elseif($fields != null , $where == null){ $this->db->limit($limit, $start); $this->db->select($fields); $query = $this->db->get($this->table); if ($query->num_rows() > 0) return $query->result(); else return false; } // return records through condition elseif($fields == null , $where != null){ $this->db->limit($limit, $start); $query = $this->db->get_where($this->table, $where); if ($query->num_rows() > 0) return $query->result(); else return false; } // return records fields through condition else{ $this->db->limit($limit, $start); $this->db->select($fields); $query = $this->db->get_where($this->table, $where); if ($query->result() > 0 ) return $query->result(); else return false; } } public function count() { return $this->db->count_all($this->table); } }
view (info.php)
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>applicants - admin</title> <link rel="stylesheet" href="<?php echo base_url('css/normalize.css'); ?> "> <link rel="stylesheet" href="<?php echo base_url('css/admin-style.css'); ?> "> </head> <body> <header> <img src="<?php echo base_url('images/path1.png'); ?>" alt=""> </header> <section> <table class="show-item"> <tbody> <th>donor details</th> <tr> <th>name</th> <th>place</th> <th>phone</th> </tr> <?php foreach ($data $key => $row) { ?> <tr> <td> <a href=""><h3><?php echo $row->name;?></h3></a> </td> <td> <p><?php echo $row->place;?></p> </td> <td> <p><?php echo $row->phone;?></p> </td> </tr> <?php } ?> </tbody> </table> <?php echo $links ?> </section> </body> </html>
did make sure you've removed index.php
url? also, if you've redefined route "info" points "example/get_details" (as see comments...), $config['uri_segment']
should set "2", , not "3".
Comments
Post a Comment