Welcome Guest, Not a member yet? Register   Sign In
Pagination Issue when I don't want to use uri->segment
#1

[eluser]ovicostea[/eluser]
Hello, I have a problem. I want to use:
Code:
$config['pagination']['use_page_numbers'] = TRUE;
Code:
$config['pagination']['uri_segment'] = FALSE;

but I see in the /system/libraries/Pagination.php on Line 158
method create_links()
Code:
// Determine the current page number.
  $CI =& get_instance();


  if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
  {
   if ($CI->input->get($this->query_string_segment) != $base_page)
   {
    $this->cur_page = $CI->input->get($this->query_string_segment);

    // Prep the current page - no funny business!
    $this->cur_page = (int) $this->cur_page;
   }
  }
  else
  {
// here is the issue and I added  "$CI->uri->segment($this->uri_segment) !== FALSE &&"
if ($CI->uri->segment($this->uri_segment) !== FALSE && $CI->uri->segment($this->uri_segment) != $base_page)
   {
    $this->cur_page = $CI->uri->segment($this->uri_segment);

    // Prep the current page - no funny business!
    $this->cur_page = (int) $this->cur_page;
   }
  }

I'm not sure if I made understand, but is no error, the problem is the pages numbers where I click on are not changed. I click on page 2 but page 2 didn't become active. But with my change in the code above is working.

Any idea how to make this change without affect the system class, or what can I do to make it work without changes ?

Thank you.
#2

[eluser]joergy[/eluser]
What's the purpose of Your changes?
Don't You want to use CI's "segments"?
$config['pagination']['uri_segment'] has to be a number and not false.

$config['page_query_string'] = TRUE is what You are looking for:
If you have $config['enable_query_strings'] set to TRUE your links will automatically be re-written using Query Strings. This option can also be explictly set. Using $config['page_query_string'] set to TRUE, the pagination link will become.
Sample: http://example.com/index.php?c=test&m=page&per_page=20
#3

[eluser]ovicostea[/eluser]
Thanks for response.
Here is an example of my link:
tasks/index/page/4 or
tasks/index/status/progress/page/4 or
tasks/index/status/all/by/johnny/page/4

Because I don't know what segment will be the page, I decided to use $this->uri->uri_to_assoc() and get the page from array
$config['cur_page'] = $arr['page];

#4

[eluser]joergy[/eluser]
So why not using the last or first segment always?
Depends on Your $config['base_url']...

Be car full with the value of $config[‘cur_page’]. I had really a hard time with this value but for me $config['pagination']['use_page_numbers'] was FALSE. I recommend walking through the code.
#5

[eluser]ovicostea[/eluser]
Thanks joergy for your time to answer, but I really want that url format.
If anybody have different solution, please posted here, I really appreciate it.
Thanks.
#6

[eluser]joergy[/eluser]
Ok. Another approach:
What about changing the config directly before calling "create_links()"?
$config['pagination']['uri_segment'] = $this->uri->total_segments() ...
#7

[eluser]ovicostea[/eluser]
Can be a solution, but I see 3 different cases in that class:
1. Using $config['pagination']['page_query_string'] = TRUE;
2. Using $config['pagination']['uri_segment'] = a number;
3. Using $config['pagination']['cur_page'] = a number;

In the method create_links() is only If and else:
if page_query_string else uri_segment and I want cur_page, no one from 1. and 2.

Maybe there is a solution, I'm sure it is, but I don't know how to implement it, without alter the system pagination class.
#8

[eluser]CroNiX[/eluser]
You could create a helper function to determine what segment it is.

something like (untested):

Code:
function get_page_from_uri($search = 'page')
{
  $CI =& get_instance();
  $uri = split('/', $CI->uri->uri_string());
  $segment = null;
  foreach($uri as $k => $v)
  {
    if ($search == $v)
    {
      $segment = $k + 2; //segments start at 1, so add 2 to get segment after this one
      break;
    }
  }
  return $segment; //will be null if not present, or the segment number if found.
}

So if the url was: tasks/index/status/progress/page/4
Code:
$config['pagination']['uri_segment'] = get_page_from_uri(); //6
#9

[eluser]joergy[/eluser]
Sorry, I give it up.
I can't see the purpose of Your desire.
'cur_page' isn't a config var for pagination but retrieved "automatically" from the calling url.
If You can set it, your script already knows on which page it is and hasn't to retrieve it.
The purpose of pagination is to automate the process of retrieving the selected page and building a set of links from this info....

Again sorry and bye bye
Joergy
#10

[eluser]ovicostea[/eluser]
Thanks CroNiX, but what about this point?
3. Using $config[‘pagination’][‘cur_page’] = a number;
Is something wrong with it and is not encourage to use it?




Theme © iAndrew 2016 - Forum software by © MyBB