• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Pagination and URI Routing Problem

#1
[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.

#2
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.