Welcome Guest, Not a member yet? Register   Sign In
Pagination not passing parameters as URI Segment
#1

[eluser]emelpy[/eluser]
I am trying to use pagination to show a list of news articles from my database. My URL structure is /admin/news/showlist/ where admin is a directory and showlist is a function in the news controller.

Here is the code:
Code:
function showlist()
    {
        $this->load->library('pagination');
        $this->load->model('Admin_model');
        $this->load->helper('url');
        
        $config['base_url'] = site_url('vantageadmin/news/showlist/');    
        $config['total_rows'] = $this->db->count_all('ast_news');
        $config['per_page'] = '10';
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';

        $offset = substr($this->uri->segment(4), strpos($this->uri->segment(4), 'per_page=') + 9);

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

        $data['results'] = $this->Admin_model->getNewsList($config['per_page'], $offset);
        
        $this->load->library('table');
        $this->table->set_heading('ID', 'Company', 'Title', 'Content', 'Posted', 'Displayed', 'Ended', 'Weight', 'Show');        
        $this->load->view('vantageadmin/news/showlist', $data);
        
    }

My problem is that CodeIgniter does not seem to be passing the per_page variable correctly. In the documentation is says that it should default to passing it as a segment e.g. /admin/news/showlist/10 where 10 is the current offset.

This is not how it is working for me. For some reason the links codeigniter is generating with pagination->create_links() look like
/admin/news/showlist/&per_page=10. This looks kind of like it's passing it via GET but when I do a var_dump on $_GET it is empty. As you can see I hacked the per_page value out of the URL using uri->segment. This works when going from page 1 to 2 but codeigniter fails to hyperlink page 1 once I am at page 2.

Any ideas on this?
#2

[eluser]Dam1an[/eluser]
Do you not need to set
Code:
$config['uri_segment'] = 4;
And why not take the offset as a param into the method then, will be much easier
#3

[eluser]emelpy[/eluser]
[quote author="Dam1an" date="1247789887"]Do you not need to set
Code:
$config['uri_segment'] = 4;
And why not take the offset as a param into the method then, will be much easier[/quote]

Hey, thanks for the quick reply. It looks like in the global config file we have $config['enable_query_strings'] = TRUE;

Adding $this->config->set_item('enable_query_strings', 'FALSE'); to the top of my showlist function fixed this for me.

You mean take offset as a param to showlist?




Theme © iAndrew 2016 - Forum software by © MyBB