Welcome Guest, Not a member yet? Register   Sign In
Help with pagination and passing anchor parms
#1

[eluser]Frank Rocco[/eluser]
Hello,

I have an anchor link that passes an id to controller/index and want to display a subset of records.

I tried setting the pagination segment to 4, but when I pass in the link, it messes up the pagination.

When I try and go to the next page, I get no results because catId is set to 5, the next page offset.

Code:
function index()
    {
        $offset = $this->uri->segment(4,0);
        $catId = $this->uri->segment(3,0);
        $this->load->library('pagination');
        $perpage = 5;
        $config['base_url'] = base_url() . 'index.php/category/index';
        $config['per_page'] = $perpage;
        $config['uri_segment'] =4;
        $config['total_rows'] = $this->category_model->getRecords(array('count' => TRUE, 'cat_parent_id' => $catId));

        $this->pagination->initialize($config);
        $data['total_rows'] = $config['total_rows'];
        $data['pagination'] = $this->pagination->create_links();
        
        $data['results'] = $this->category_model->getRecords(
            array('limit' => $perpage,
                    'offset' => $offset,
                    'cat_parent_id' => $catId,
                    'sortBy' => 'cat_name',
                    'sortDirection' => 'ASC'
            ));
#2

[eluser]bretticus[/eluser]
My guess would be try to add your category variable to the base_url config:

Code:
function index()
    {
        $offset = $this->uri->segment(4);
        $catId = $this->uri->segment(3);
        $this->load->library('pagination');
        $perpage = 5;
        $config['base_url'] = base_url() . 'index.php/category/index/' . filter_var($catID, FILTER_SANITIZE_NUMBER_INT); //might as well filter anything else out for safety.
        $config['per_page'] = $perpage;
        $config['uri_segment'] =4;
        $config['total_rows'] = $this->category_model->getRecords(array('count' => TRUE, 'cat_parent_id' => $catId));

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




Theme © iAndrew 2016 - Forum software by © MyBB