CodeIgniter Forums
[SOLVED] Pagination and URI Routing Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED] Pagination and URI Routing Problem (/showthread.php?tid=10917)



[SOLVED] Pagination and URI Routing Problem - El Forum - 08-18-2008

[eluser]Rob Rightmyer[/eluser]
We are having problems using pagination in conjunction with URI routing.

Things are working as expected except the "current" page is not advancing when each pagination link is clicked.

Routes.php:
Code:
$route['gallery2/:num'] = "gallery2/index";

Gallery2.php (controller):
Code:
<?php

class Gallery2 extends Controller {

    function Gallery2()
    {
        parent::Controller();

        //Load the HTML, URL and Form helpers
        $this->load->helper('html');
        $this->load->helper('url');
        $this->load->helper('form');
    }

    function index()
    {
        //Load the Database class
        $this->load->database();
        
        //Load the pagination libarary, setup pagination variables, initialize pagination
        $this->load->library('pagination');
        $config['base_url'] = base_url().'gallery2';
        $config['total_rows'] = $this->db->count_all('gallery');
        $config['per_page'] = '8';
        $config['num_links'] = '100';
        $this->pagination->initialize($config);

        //Sort the database results
        $this->db->order_by('id', 'desc');

        //Query the database
        $data['query'] = $this->db->get('gallery', $config['per_page'],$this->uri->segment(2));

        //Load the Photo Gallery view        
        $this->load->view('gallery2', $data);
        }
}
?>

If I've ommitted any information that would be helpful in solving this please let me know.


[SOLVED] Pagination and URI Routing Problem - El Forum - 08-19-2008

[eluser]Rob Rightmyer[/eluser]
After a little more digging, I found my answer here:
http://ellislab.com/forums/viewthread/87304/

Needed to add this config line to my pagination:
$config['uri_segment'] = '2';

Everything works great now.