Welcome Guest, Not a member yet? Register   Sign In
Problems with Pagination
#1

[eluser]happydude[/eluser]
I have just been trying to get the pagination library to work to no avail.

Pagination works fine at other parts of the application where I am working on except this part.

The problem is that when I open the page. The pagination works fine, but when I click any other number in the pagination links, the cur_tag_open and the cur_tag_close are still set to the first page (1). Also, its link points to the current page on which it is located, so rather than have categories/1, I have categories/1/18 as the link on it.

Here is my code below:

Code:
function index($slug='', $id='', $offset=0)
    {
        if ( ! ($slug && $id ) ) { //No params? Bounce to home page
            redirect ('home');
        }
        
        $products_per_page = 6;
        
        $this->data = $this->category->get($id);
        $this->_sidebar(); //Generate the sidebar.
        
        $this->data['products'] = $this->product->get_products($products_per_page, (int)$offset, (int)$id, 'category');
        
        //Generate Pagination
        $this->load->library('pagination');

        $config['base_url'] = base_url().'categories/'.$slug.'/'.$id.'/';
        $config['total_rows'] = $this->product->count_by('category_id', $id);
        $config['per_page'] = $products_per_page;

        $this->pagination->initialize($config);
        
        var_dump($config['total_rows']);

        $this->data['pagination'] = $this->pagination->create_links();
    }
#2

[eluser]srpurdy[/eluser]
Not sure if you're offset should be 0? Maybe I'm wrong, normally how I would do it is like below.

Controller
Code:
$this->load->library('pagination');
$config['base_url'] = base_url(). 'leagues/show/' . $this->uri->segment(3);
$config['per_page'] = '5';
$config['uri_segment'] = '4';
$config['num_links'] = '4';
$data['blog'] = $this->blog_model->get_blogposts($config['per_page'],$this->uri->segment(4));
$data['count_posts'] = $this->blog_model->count_results();
$config['total_rows'] =   count($data['count_posts']->result());
$this->pagination->initialize($config);

Model
Code:
function get_blogposts($num, $offset)
{    
    $get_posts = $this->db        
        ->where('ilr_league.url_league_name', $this->uri->segment(3))
        ->where('ilr_league.league_id = ilr_blog.league_id')
        ->where('ilr_blog.active', 'Y')
        ->select('*')
        ->from('
            ilr_blog,
            ilr_league
        ')
        ->limit($num, $offset)
        ->order_by('ilr_blog.date', 'desc')
        ->get();
    return $get_posts;
}
#3

[eluser]happydude[/eluser]
Its not so different. Your $this->uri->segment(4) is typecasted to 0 for the first set of results.

I have a nasty feeling this problem has to do with the router class... because I have set it up to route from site/categories/index/category_id/page_id to site/categories/category_id/page_id




Theme © iAndrew 2016 - Forum software by © MyBB