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

[eluser]peekk[/eluser]
Hello, I have a weird problem with pagination, my configuration is:
Code:
function searcher($keyword=''){
    (...)
    $this->load->library('pagination');

    $config['base_url'] = base_url().'search/searcher/'.$keyword.'/';
    $config['total_rows'] = '100';  
    $config['full_tag_open'] = '<p>';
    $config['full_tag_close'] = '</p>';
$config['per_page'] = 25;


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

    $offset = $this->uri->segment(4);
  if(!$offset){$offset=0;}      
    
    $answer = new stdClass;
    $answer = $this->searchermodel->search($kryteria, 25, $offset, $keyword,'');
}

And my problem is, when i'm searching for something, i.e. "computer". My results are displayed, first page URL is: example.com/search/searcher/computer/0. Now, when I click on my page link, i.e. page 2, URL changes to example.com/search/searcher/computer/25, seems good. Results are correct too. My only problem is my pagination links below. It doesn't mean if i'm on page 1 or page 15, it's always the number 1 bolded. Results are correct, URL is correct, but I ALWAYS see this:
Quote:1 2 3 > Last ›
. What's wrong?
#2

[eluser]InsiteFX[/eluser]
Your not passing the page offset to it!
Code:
$config['base_url'] = base_url().'search/searcher/'.$keyword.'/';
#3

[eluser]meigwilym[/eluser]
What you need is to pass the uri_segment to the config
Code:
$config['uri_segment'] = 4;

Mei
#4

[eluser]Mauricio de Abreu Antunes[/eluser]
[quote author="meigwilym" date="1329923253"]What you need is to pass the uri_segment to the config
Code:
$config['uri_segment'] = 4;

Mei[/quote]
Code:
$segment = 4;
$config['uri_segment'] = $segment;
$offset  = $this->uri->segment($segment);

#5

[eluser]meigwilym[/eluser]
@mauricio I'm not sure what you're trying to tell me here. Can you expand a bit?

* Scratch that, looking at the original code I now see what you mean. Thanks.

Mei
#6

[eluser]Mauricio de Abreu Antunes[/eluser]
[quote author="meigwilym" date="1329923969"]@mauricio I'm not sure what you're trying to tell me here. Can you expand a bit?

* Scratch that, looking at the original code I now see what you mean. Thanks.

Mei[/quote]

You are welcome!
I coded a method in my MY_Controller to control pagination config.
And obviously, a config in application/config/upload.php.

Bye!
#7

[eluser]peekk[/eluser]
Thanks, advice about setting an uri segment in config array worked like a charm : )
#8

[eluser]peekk[/eluser]
I have 1 more question, and i think it's not worth to create a new topic for it (it seems not hard). How can i do, that my links will be example.com/search/searcher/<OFFSET>/keyword - I mean I want to change the order of keyword and offset of my URLs, I was trying by routing, but I couldn't do this. My try was about that:

Code:
function searcher(offset=0,$keyword=''){
    (...)
    $this->load->library('pagination');

    $config['base_url'] = base_url().'search/searcher/'.$offset.'/'.$keyword.'/';
    $config['total_rows'] = '100';  
    $config['full_tag_open'] = '<p>';
    $config['full_tag_close'] = '</p>';
    $config['per_page'] = 25;
    $config['uri_segment']=3

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

    $offset = $this->uri->segment(3);
  if(!$offset){$offset=0;}      
    
    $answer = new stdClass;
    $answer = $this->searchermodel->search($kryteria, 25, $offset, $keyword,'');
}

I just need to change order in URLs, and make it work. How to do it?
#9

[eluser]aquary[/eluser]
The "append URI" is not supported by CI's pagination. I guess you have to extend the pagination library and add a new configuration yourself.
#10

[eluser]peekk[/eluser]
[quote author="aquary" date="1330007875"]The "append URI" is not supported by CI's pagination. I guess you have to extend the pagination library and add a new configuration yourself.[/quote]

Allright, thanks ; )




Theme © iAndrew 2016 - Forum software by © MyBB