Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 1.33 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Codeigniter Pagination URL issue
  2. http://www.reviewongadgets.com/home/10
  3.        
  4. http://www.reviewongadgets.com/home/home/
  5.        
  6. $config['base_url'] = $url;
  7. $config['total_rows'] = $this->MiscellaneousModel->countEntries();
  8. $config['per_page'] = 10;
  9. $base_url = site_url('/');
  10. $config['uri_segment'] = '2';
  11. //$config['page_query_string'] = TRUE;
  12. $this->pagination->initialize($config);
  13.        
  14. $config['base_url'] = site_url('home');
  15. $config['total_rows'] = $this->MiscellaneousModel->countEntries();
  16. $config['per_page'] = 10;
  17. $config['uri_segment'] = '2';
  18.        
  19. $config['base_url'] = site_url('home/index');
  20.        
  21. //Add this to your routes
  22. $route['home/(:num)'] = 'home/index/$1';
  23.  
  24.  
  25. public function index($offset=0){
  26.  
  27. $limit = $this->config->item('pagination_per_page'); // default 10
  28.  
  29. //find data based on limits and offset
  30. $query = //you query LIMIT = $limit OFFSET = $offset
  31.  
  32. $count = //count the number of rows returned by $query
  33.  
  34. //init pagination attributes
  35. $config = array(
  36.         'base_url' => site_url('home'),
  37.         'total_rows' => $count,
  38.         'per_page' => $limit,
  39.         'uri_segment' => 2
  40.     );
  41. $this->pagination->initialize($config);
  42.  
  43. //load the view and pagination data
  44. $this->load->view('some_view', array(
  45.         'pagination'  =>  $this->pagination->create_links(),
  46.         'data'  => //data return from $query as object or array
  47. ));
  48. }