• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination links showing up incorrectly

#1
[eluser]kaosweaver[/eluser]
Ok, so, I've got a separate cache routine going from CI, (it is working fine and merges with the existing cache system on a site I'm redoing) and I've got hashtag page loading going on with some re-routing (which is also working as expected). What the issue is when the subsequent pages are accessed from the page result, it always shows the pagination link at the last number (as active), although the content of the page is the right content.

Code:
public function index($tag,$start='',$end='',$start_pos=0,$limit=20)
{
  // Load models, scrub date range, etc.

  // this line checks to see if the page is cached, and if it is, just load it
  $data['content']=$cache->retrieve("tag_".$tag."_".$start."_".$end."_".$start_pos,"tag_content");
  if (!$data['content']) {
   // gets all articles
   $counter=$this->Articles->get_articles_by_tag($tag,$start,$end,0,1000000000);
   // gets the articles with the page limit applied
   $subdata['articles']=$this->Articles->get_articles_by_tag($tag,$start,$end,$start_pos,$limit);
  
   $this->load->library('pagination');
   // SITE ROOT is a defined constant
   $config['base_url'] = SITE_ROOT.'/tags/'.$tag."/".$start."/".$end."/";
   $config['total_rows'] = $counter->num_rows();
   $config['per_page'] = $limit;
   $this->pagination->initialize($config);
   $subdata['links'] = $this->pagination->create_links();
   $subdata['tag']=$tag;
   $data['content']=$this->load->view("tags/main_content",$subdata, true);
   $cache->store( "tag_".$tag."_".$start."_".$end."_".$start_pos, $data['content'], "tag_content", $cache_time);
  }
  $this->load->view('layout',$data);
}
So, the code should store each page in the cache, with the start_pos as the different keys for each of the cache section (this is actually working fine) - however, the pagination links always have the last numbers showing and the last number set to active regardless of what page you're on after the first page loads.

Any ideas? Any other code files needed? (this is a site in the making, it isn't available to view online, I'll provide screenshots and code samples if needed)

Your help is appreciated.

#2
[eluser]Aken[/eluser]
You need to tell the pagination class what page it's on, using the uri_segment config option. The user guide is misleading - it doesn't actually guess the URI segment, it just defaults to a specific one (3).

#3
[eluser]kaosweaver[/eluser]
Thanks, that was it, I was confused because the docs said:

"The pagination function automatically determines which segment of your URI contains the page number."

and I took that to mean it could count the number of segments in the base_url variable and then add one for the pagination location Smile

#4
[eluser]Aken[/eluser]
You're definitely not the only person.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.