Route and Pagination |
Hi everyone!
I need your help with routes and pagination. I am creating a tags page and can't figure out how to setup my route and pagination to work properly. Here is my route Code: $route['tag/(:any)/(:num) = 'tag/page/$1'; Here is my pagination code PHP Code: $id = $this->model->get_tag_id($this->uri-segment(2); The final question I have is how to use $data['per_page'] and $this->uri->segment(number) if you I create an own query with UNION ALL like this: Code: $this->db->query("SELECT total.* FROM ( Hopefully someone can help me with these two problems. Best regards. Headpetrol
No need to define a route for particular pagination
define code below for pagination controller ============= Controller ================ $config = [ 'base_url' => base_url('controlor_name/function'), 'per_page' =>"number of per page records", 'total_rows' => "total_records", ]; if($this->uri->segment(3)){ $page = ($this->uri->segment(3)) ; } else{ $page = 0; } $this->pagination->initialize($config); $this->pagination_model->fetch_data('tablename',$per_page, $page ); ============ Function for Model ============ public function fetch_data($tabel_name , $limit, $id ) { $this->db->limit($limit, $id); $this->db->order_by("id","desc"); $query = $this->db->get($tabel_name); return $query->result_array(); } I hope this will help you ![]()
In your example, is tag the controller and page method?
In that case you need to add one more argument to router code - $2 to get page number PHP Code: $route['tag/(:any)/(:num) = 'tag/page/$1/$2'; And controller class: PHP Code: class Tag extends CI_controller |
Welcome Guest, Not a member yet? Register Sign In |