Tony
Tony

Reputation: 351

Pagination with codeigniter URI issue

This is my first time working with pagination in codeigniter and I'm a little confused. I believe my problem may have something to do with the URI segments offset variable.

Here's my controller. I have replaced the $config["base_url"] with the full URL so you can see how many URI segments I have.

My controller

        $gutterId = $this->gutter->convertGutterNameToId($name);
        $this->load->library("pagination");
        $config = array();
        $config["base_url"] = "http://localhost/gutter/g/random/";     //base_url() . "/g/$name";
        $config["total_rows"] = $this->gutter->countThreadRows($gutterId);
        $config["per_page"] = 1;
        $config["uri_segment"] = 5;

        $this->pagination->initialize($config);

        $limit = 1;
        $offset = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;

        $data['threads'] = $this->gutter->grabThreads($limit, $offset, $gutterId);
        $data['title'] = $name;
        echo $this->pagination->create_links();

And my model.

 public function grabThreads($limit, $offset, $gutterId){
            $query = $this->db->limit($limit, $offset)->order_by('thread_id', 'DESC')->get_where('threads', array('thread_sub_gutter' => $gutterId));

            return $query->result();
        }

So this is giving me one result on the http://localhost/gutter/g/random/ page which leads me to believe the query is working correctly. However, when I navigate to http://localhost/gutter/g/random/1 I get the following 404 error

The page you requested was not found.

Upvotes: 1

Views: 466

Answers (1)

Callombert
Callombert

Reputation: 1099

You will need to route the request to your controller. Should be something like this:

$route['g/(:any)/(:any)'] = 'g/index/$1/$2';

Also if your page number is going to be in the third segment, do this:

$config[‘uri_segment’] = 3;

Upvotes: 1

Related Questions