Advertisement
Guest User

CI - Pagination

a guest
Jan 29th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2. class Order extends Controller {
  3.  
  4.     // search data
  5.     function browse_search() {
  6.  
  7.         if(empty($_POST['field_content'])) {
  8.             $field_content = 0;
  9.         } else {
  10.             $field_content = $_POST['field_content'];
  11.         }
  12.  
  13.  
  14.         if(empty($_POST['limit'])) {
  15.             $limit = 10;
  16.         } else {
  17.             $limit = $_POST['limit'];
  18.         }
  19.  
  20.         redirect('order/browse_result/'.$field_content."/".$limit);
  21.  
  22.     }
  23.  
  24.     // search result
  25.     function browse_result($field_content = '', $limit = 10, $start = 0)    {
  26.  
  27.         if($field_content !== '0') {
  28.             $object['data']['field_content'] = $field_content;
  29.         } else {
  30.             $object['data']['field_content'] = '';
  31.         }
  32.  
  33.         $object['data']['limit'] = $limit;
  34.         $object['data']['start'] = $start;
  35.  
  36.         $object['sort_link'] = 'order/browse_result/'.$field_content.'/'.$limit.'/';
  37.  
  38.         $this->load->library('pagination');
  39.  
  40.         $config['per_page'] = $limit;
  41.         $config['num_links'] = 6;
  42.         $config['first_link'] = "&lt;&lt;";
  43.         $config['last_link'] = "&gt;&gt;";
  44.         $config['prev_link'] = "&lt;";
  45.         $config['next_link'] = "&gt;";
  46.  
  47.         $config['uri_segment'] = 4; // 3, 4, 5, atau 6, coba-coba aja
  48.         $config['base_url'] = site_url('order/browse_result/'.$field_content.'/'.$limit.'/');
  49.  
  50.         $config['total_rows'] = $this->m_order->orders_count_by_criteria($field_content); // orders_count_by_criteria menghitung jumlah baris berdasarkan content
  51.  
  52.         // save pagination definition
  53.         $this->pagination->initialize($config);
  54.  
  55.         $object['limit'] = $limit;
  56.         $object['total_rows'] = $config['total_rows'];
  57.  
  58.         $this->template->write_view('content', 'order/order_browse', $object);
  59.         $this->template->render();
  60.  
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement