2015-09-22 123 views
0

我正在嘗試使用codeigniter 3和bootstrap twitter分頁。當我點擊鏈接分頁它總是給我404找不到。codeigniter分頁404找不到

我覺得這是我的不完全理解笨URI故障,這就是爲什麼我在我的代碼

這裏需要幫助的是我的模型:

class Mcrud extends CI_Model { 

    public function record_count() { 
     return $this->db->count_all("crud"); 
    } 

    function view() { 
    $ambil = $this->db->from('crud')->order_by('idcrud', 'DESC')->limit(5, 3)->get(); 
     if ($ambil->num_rows() > 0) { 
      foreach ($ambil->result() as $data) { 
       $hasil[] = $data; 
      } 
      $ambil->free_result(); 
      return $hasil;   
     } 
    } 

這裏是我的控制器:

class Chome extends CI_Controller { 
function __construct() { 
    parent::__construct(); 
    $this->load->model('Mcrud'); 

} 

function index() { 
    if($this->session->userdata('logged_in')) 
    { 
     $session_data = $this->session->userdata('logged_in'); 
     $data['nama'] = $session_data['fullname']; 
     $data['username'] = $session_data['username']; 
     $data['id'] = $session_data['idlogin']; 

     $this->load->view('Header', $data); 
     $this->suratkeluar(); 

    } else { 
     redirect('welcome', 'refresh'); 
    } 
} 

function suratkeluar() 
{ 
    $result_per_page = 2; // the number of result per page 

    $config['base_url'] = base_url() . '/Chome/index'; 
    $config['total_rows'] = $this->Mcrud->record_count(); 
    $config['per_page'] = $result_per_page; 
    $config['use_page_numbers'] = TRUE; 
    $config['num_links'] = 20; 
    $config["uri_segment"] = 3; 
    $this->pagination->initialize($config); 

    $data['data_get'] = $this->Mcrud->view(); 
    $data['pagination'] = $this->pagination->create_links(); 

    $this->load->view('Vhome', $data); 
    $this->load->view('Footer'); 
} 

這是我的Vhome視圖:

<div class="table-responsive"> 
    <table class="table table-bordered table-hover table-striped"> 
     <caption>List Data</caption> 
     <thead> 
     <tr> 
      <th width="80px">ID</th> 
      <th>First Name</th> 
      <th>Last Name</th> 
      <th>Age</th> 
      <th>Address</th> 
      <th width="80px">Action</th> 
     </tr> 
     </thead> 
     <tbody> 
     <?php 
     if ($data_get == NULL) { 
     ?> 
     <div class="alert alert-info" role="alert">Data masih kosong, tolong di isi!</div> 
     <?php 
     } else { 
     foreach ($data_get as $row) { 
     ?> 
     <tr> 
      <td><?php echo $row->idcrud; ?></td> 
      <td><?php echo $row->firstname; ?></td> 
      <td><?php echo $row->lastname; ?></td> 
      <td><?php echo $row->age; ?></td> 
      <td><?php echo $row->address; ?></td> 
      <td> 
      <a href="<?php echo site_url('Chome/edit/' . $row->idcrud); ?>" class="btn btn-warning btn-xs"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a> 
      <a href="<?php echo site_url('Chome/delete/' . $row->idcrud); ?>" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a> 
      </td> 
      <?php 
      } 
     } 
      ?> 
     </tr> 
     </tbody> 
    </table> 
    <?php echo $pagination; ?> 
</div> 

最後這是我在config.php中的基礎url:

$ config ['base_url'] ='http://localhost/arsip/';

+0

什麼是你所得到的404網址?你試過'$ config ['base_url'] = site_url()'而不是'$ config ['base_url'] = base_url()'? – Craig

+0

http:// localhost/arsip/chome/index/2總是收到404錯誤。 並感謝site_url()正在工作:D,沒有得到404錯誤了。我想知道有什麼不同。 現在我堅持爲什麼結果沒有改變後,我點擊該鏈接 –

+0

因爲你的查詢不是動態的,看看你的限制聲明。 – AkshayP

回答

0

試圖修改本節:

型號:

function view($opset) { 
    $ambil = $this->db->from('crud')->order_by('idcrud', 'DESC')->limit(5, $opset)->get(); 
    if ($ambil->num_rows() > 0) { 
     foreach ($ambil->result() as $data) { 
      $hasil[] = $data; 
     } 
     $ambil->free_result(); 
     return $hasil;   
    } 
} 

控制器:

function suratkeluar($opset=NULL) 
{ 
    $result_per_page = 2; // the number of result per page 

    $config['base_url'] = base_url('Chome/suratkeluar'); 
    $config['total_rows'] = $this->Mcrud->record_count(); 
    $config['per_page'] = $result_per_page; 
    $config['use_page_numbers'] = TRUE; 
    $config['num_links'] = 20; 
    $config["uri_segment"] = 3; 
    $this->pagination->initialize($config); 

    $data['data_get'] = $this->Mcrud->view($opset); 
    $data['pagination'] = $this->pagination->create_links(); 

    $this->load->view('Vhome', $data); 
    $this->load->view('Footer'); 
} 

工作:)

+0

我只需要創建動態限制opset的權利? 由於某種原因,很奇怪,不適合我.. –

+0

https://github.com/SunDi3yansyah/buat-mas-La-Croix-paginationnya 不太好,我... 已經我直接給你存儲庫,再次騰空.... 祝你好運:) – SunDi3yansyah

+0

它的工作現在,我只需要設置$ opset = $ this-> uri-> segment(3);感謝您的幫助:) –