Welcome Guest, Not a member yet? Register   Sign In
Pagination + URI Routing problem.
#1

[eluser]Unknown[/eluser]
First of all: a short sketch of my layout: I'm creating a (pretty simple) website, where each method ends with a .html extension.

Code:
$config['url_suffix'] = ".html";

So far, so good. Yet, the pagination + URI routing problem occurs with one particular method, which is being routed like this:
Code:
$route['publications'] = "publication/index";

That means that if someone browses to http://domain/publications.html it is being routed to the publication controller and the index method.

What I'm trying to accomplish is the following: the publication controller and the index method should be displaying a paginated list of 10 publications per page. Thanks to a tutorial I found on the Godbit Project, I could compose the following (working) lines of code:

Code:
$this->load->library('pagination');
    $config['base_url'] = base_url().'publications.html?';
    $config['total_rows'] = $this->db->count_all('publications');
    $config['per_page'] = '10';
    $config['page_query_string'] = TRUE;
    $config['full_tag_open'] = '<p>';
    $config['full_tag_close'] = '</p>';

    $this->pagination->initialize($config);
        
    //load the model and get results
    $this->load->model('publications');
    $data['results'] = $this->publications->get_publications($config['per_page'],$this->uri->segment(2));
        
    // load the view
    $this->load->view('view_publication', $data);

Yet, the pagination links don't seem to be working the way I want them. I want links to display (and function) as: http://domain/publications.html?per_page=X where X functions as the offset.

What am I missing?
#2

[eluser]xwero[/eluser]
You are mixing a lot of things. Here is a breakdown

The pagination and the url are PATH_INFO based but you want the pagination to be GET based. The problem with this is that even if you allow query_strings to be used the pagination library will look for a PATH_INFO segment.

Using the suffix in the base url will have wierd results i guess because the pagination library is not controlling the adding of the suffix.

The fastest way i can think of to solving this is writing your own pagination class or search for a pagination class. Modifying the CI library will take a lot longer, but if you are willing to do it i'm not holding you back Wink
#3

[eluser]maesk[/eluser]
It's difficult to say without seeing the rest of your code (namely the model) and without knowing in what way your pagination links behave unexpectedly... but what's with the $this->uri->segment(2) your passing into your model? Apparently you're using query strings.

Quote from the User Guide:
Quote:Please note: If you are using query strings you will have to build your own URLs, rather than utilizing the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with segment based URLs.




Theme © iAndrew 2016 - Forum software by © MyBB