Welcome Guest, Not a member yet? Register   Sign In
Pagination - Goto Last page [fixed]
#1

[eluser]happs74[/eluser]
Hi,

I've hunted about for this and there sure seem to be a lot of pagination queries so apologies for adding to them. A lot of them seemed to be solved by using uri_segment but my problem is trying to step round it. I'm knocking up a simple forum and when a user adds a new post they should go to the last page of the topic to see their post.

In my addmessage controller function after it's done all it's magic is redirects via

Code:
redirect('messageboard/viewboard/viewtopic/'.$topic_id.'/last');

and at the top of my viewtopic function I have

Code:
$topic_id = $this->uri->segment(4,0);
$pageno = $this->uri->segment(5,0);
$total_rows = %this->messages->getMessageCount($topic_id);
if($pageno == 'last')
{
  #Get the offset of the last page
  $pageno = $total_rows - ($total_rows % $this->config->item('message_per_page'));
}

My problem is that the $config['uri_segment'] = 5 that I pass to the pagination->initialize function pulls in the 'last' string, is there anyway to override it to pass in my calculated page offset.

Cheers in advance.
#2

[eluser]happs74[/eluser]
Managed to fix it, problem was down to my lack of PHP knowledge again, who'd have thunk that strings evaluate to 0. Anyhoo if anyone else runs into the same problem I fixed it by making a quick change to the Pagination class, it looks kinda ugly this early in the morning but it'll do the trick before I come up with something cleaner.

I replaced the if block in create_links that just below the comment #Determine the current page number to

Code:
if( (string)$CI->uri->segment($this->uri_segment) != '0')
{
  if( (string)$CI->uri->segment($this->uri_segment) == 'last')
  {
    $this->cur_page = $this->cur_page = ((ceil($this->total_rows/ $this->per_page))-1) * $this->per_page;
  }
  else
  {
    if( ! is_numeric($this->cur_page))
    {
      $this->cur_page = 0;
    }
    else
    {
      $this->cur_page = $CI->uri->segment($this->uri_segment);
    }
  }
}

Edited cos I screwed up the cur_page calculation, it's a bit ugly and I need to do the same thing in my controller so I can pass it to model to select the correct block with limit.




Theme © iAndrew 2016 - Forum software by © MyBB