php - Pagination in Codeigniter returns error -


my problem pagination not working, shows number of pages << 1 2 3 >> etc... when tried go on page 2 gives me error like:

the requested url /mysite/welcome/index/2 not found on server. 

here model called: country.php

<?php defined('basepath') or exit('no direct script access allowed');  class country extends ci_model { public function __construct() {     parent::__construct(); }  public function record_count() {     return $this->db->count_all("news"); }  public function fetch_countries($limit, $start) {     $this->db->limit($limit, $start);     $query = $this->db->get("news");      if ($query->num_rows() > 0) {         foreach ($query->result() $row) {             $data[] = $row;         }         return $data;     }     return false;    } } 

here controller shows news on page, , pagination, unfortunately said when try go page 2 returns error message.

my controller called welcome.php

 class welcome extends ci_controller {  /**  * index page controller.  *  * maps following url  *      http://example.com/index.php/welcome  *  - or -  *      http://example.com/index.php/welcome/index  *  - or -  * since controller set default controller in  * config/routes.php, it's displayed @ http://example.com/  *  * other public methods not prefixed underscore  * map /index.php/welcome/<method_name>  * @see https://codeigniter.com/user_guide/general/urls.html  */  public function __construct() {     parent::__construct();     $this->load->model('news_model');     $this->load->helper('url_helper');     $this->load->model("country");     $this->load->library("pagination"); }   public function index() {     $config = array();     $config["base_url"] = base_url('') . "welcome/index";     $config["total_rows"] = $this->country->record_count();     $config["per_page"] = 2;     $config["uri_segment"] = 3;      $this->pagination->initialize($config);      $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;     $data["results"] = $this->country->         fetch_countries($config["per_page"], $page);     $data["links"] = $this->pagination->create_links();      $data['news'] = $this->news_model->get_news();     $data['title'] = 'news archive';      $this->load->view('index', $data);  }  public function view($slug = null) {     $data['news_item'] = $this->news_model->get_news($slug);      if (empty($data['news_item']))     {             show_404();     }      $data['title'] = $data['news_item']['title'];      $this->load->view('view', $data); } } 

the routes default one

 $route['default_controller'] = 'welcome'; 

also can see news , pagination on homepage:

localhost/mysite 

i hope clear, please me out why pagination not working.

thanks kind help.

do controller

public function managecategory() {         $this->load->helper(array('form', 'url'));         $this->load->view('moderator/templates/header');         $this->load->view('moderator/templates/sidebar');         $parent = '0';         $data['catdata'] = $this->b2bcategory_model->form_select($parent);         $this->load->library('pagination');         // bootstrap style maintaining pagination         $config = array();         $config["base_url"] = base_url() . "moderator/b2bcategory/managecategory";         $config["total_rows"] = $this->b2bcategory_model->record_count();         $config["per_page"] = 20;         $config["uri_segment"] = 4;         $config['full_tag_open'] = '<ul class="pagination">';         $config['full_tag_close'] = '</ul>';         $config['first_link'] = 'first';         $config['last_link'] = 'last';         $config['first_tag_open'] = '<li>';         $config['first_tag_close'] = '</li>';         $config['prev_link'] = '&laquo';         $config['prev_tag_open'] = '<li class="prev">';         $config['prev_tag_close'] = '</li>';         $config['next_link'] = '&raquo';         $config['next_tag_open'] = '<li>';         $config['next_tag_close'] = '</li>';         $config['last_tag_open'] = '<li>';         $config['last_tag_close'] = '</li>';         $config['cur_tag_open'] = '<li class="active"><a href="#">';         $config['cur_tag_close'] = '</a></li>';         $config['num_tag_open'] = '<li>';         $config['num_tag_close'] = '</li>';         $this->pagination->initialize($config);         $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;         $data["results"] = $this->b2bcategory_model->fetch_data($config["per_page"], $page);         $data["links"] = $this->pagination->create_links();         $this->load->view('moderator/managecategory', $data);         $this->load->view('moderator/templates/footer');     } 

in model

 public function fetch_data($limit, $start) {         $this->db->limit($limit, $start);          $query =   $this->db->get_where("jil_category",  array('ctg_parent'=>'0'));           if ($query->num_rows() > 0) {             foreach ($query->result() $row) {                 $data[] = $row;             }             return $data;         }         return false;    } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -