ltdev
ltdev

Reputation: 4467

Codeigniter pagination not worrking returns 404

Hi I'd like some help please. I 'm having two controllers: movies.php and actors.php where I list all actors and all movies in them.

For example this is the method for listing all my movies

public function index() {
        // count all movies
        $total = $this->movie_model->count();

        // set up pagination
        $per_page = 10;
        if ($total > $per_page) {
            $this->load->library('pagination');
            $config['base_url'] = site_url($this->uri->segment(1) . '/');
            $config['total_rows'] = $total;
            $config['per_page'] = $per_page;
            $config['uri_segment'] = 2;
            $this->pagination->initialize($config);
            $this->data['pagination'] = $this->pagination->create_links();
            $offset = $this->uri->segment(2);
        }
        else {
            $this->data['pagination'] = '';
            $offset = 0;
        }
        // fetch the movies
        $this->db->limit($per_page, $offset);
        $this->data['movies'] = $this->movie_model->get();

        // load the view
        $this->view('movies/index');
    } 

and for listing all actors

public function index() {
        // count all actors
        $total = $this->actor_model->count();

        // set up pagination
        $per_page = 10;
        if ($total > $per_page) {
            $this->load->library('pagination');
            $config['base_url'] = site_url($this->uri->segment(1) . '/');
            $config['total_rows'] = $total;
            $config['per_page'] = $per_page;
            $config['uri_segment'] = 2;
            $this->pagination->initialize($config);
            $this->data['pagination'] = $this->pagination->create_links();
            $offset = $this->uri->segment(2);
        }
        else {
            $this->data['pagination'] = '';
            $offset = 0;
        }
        // fetch the movies
        $this->db->limit($per_page, $offset);
        $this->data['actors'] = $this->actor_model->get();

        // load the view
        $this->view('actors/index');
    }

I have set my routes like this

$route['default_controller'] = "movies";
$route['404_override'] = '';
$route['movies'] = 'movies/index';
$route['actors'] = 'actors/index';

And the urls are like this

h**p: //localhost/www/task/public/  // for movies (default controller)
h**p: //localhost/www/task/public/actors // for actors controller

The problem is when I try to click a panination link to get the next records in each controller I get a 404 error. I have tried to change my config settings in pagination but no luck.

Any help would be appreciated.

Upvotes: 2

Views: 374

Answers (2)

user4419336
user4419336

Reputation:

I have link here very help full for pagination and sortable table links this may help.

http://forum.codeigniter.com/thread-1198.html

Upvotes: 1

Vinod VT
Vinod VT

Reputation: 7159

Change $config['base_url'] = site_url($this->uri->segment(1) . '/'); to,

$config['base_url'] = base_url().'movies/index'; 

and

$config['base_url'] = base_url().'actors/index';

And $config['uri_segment'] = 3;

Upvotes: 0

Related Questions