2011-05-27 92 views
2

我的代碼存在一些問題,我無法解決。 我使用CI 1.7.2。 我已經在系統中正確實施了CI分頁。 結果顯示正常,但分頁中的鏈接無法正確顯示。Codeigniter分頁

例如,如果我在頁面上點擊2,則結果顯示爲每第2頁,但目前的鏈接頁碼數保持爲1應更改爲2

下面是已經實施的代碼

$total = $this->bmodel->countResultsBanner(); 

    $data['total'] = $total; 

    $uri_segment = $this->uri->segment(4); 

    if($uri_segment == 0 || empty($uri_segment)){ 
    $uri_segment = 0; 
    } 

    $perPage = 5; 



    $config['base_url'] = base_url()."index.php/modules/banner/index"; 

    $config['total_rows'] = $total; 

    $config['per_page'] = $perPage; 

    $config['num_links'] = 4; 

    //$config['cur_tag_open'] = '<b><span class="current_page">'; 

    //$config['cur_tag_close'] = '</span></b>'; 

    $this->pagination->initialize($config); 

    $result = $this->bmodel->getAllBanners($perPage,$uri_segment); 


    $data['result'] = $result; 

提前致謝。

Ĵ

+0

你能提供更多信息嗎?編碼部分 – royrui 2011-05-27 12:39:09

+0

@royrui我已將代碼添加到最初的問題中。請檢查。謝謝J – 2011-05-27 12:46:17

回答

7

Heyy,

我也面臨着同樣的問題。最終,解決方案變得非常簡單。 :)

默認情況下,CI假設用於分頁的uri段爲(3)。在你的情況下,對你而言(我假裝無恥)是不正確的。

$config['base_url'] = base_url()."index.php/modules/banner/index"; 
$config['total_rows'] = $total; 
$config['per_page'] = $perPage; 
$config['num_links'] = 4; 

$config['uri_segment'] = 3; /* segment of your uri which contains the page number */ 

$this->pagination->initialize($config); 

希望這能解決你的問題

+0

我已經編寫了有關Codeigniter分頁的教程。 https://www.cloudways.com/blog/pagination-in-codeigniter/。看看並提出建議 – 2017-11-24 13:50:34

1

確定...試試這個...

$total = $this->bmodel->countResultsBanner(); 

    $data['total'] = $total; 

/* Comment out this part 
     $uri_segment = $this->uri->segment(4); 

     if($uri_segment == 0 || empty($uri_segment)){ 
     $uri_segment = 0; 
     } 
    */ 
    $perPage = 5; 



    $config['base_url'] = base_url()."index.php/modules/banner/index"; 

    $config['total_rows'] = $total; 

    $config['per_page'] = $perPage; 

    $config['num_links'] = 4; 

    //$config['cur_tag_open'] = '<b><span class="current_page">'; 

    //$config['cur_tag_close'] = '</span></b>'; 

    $this->pagination->initialize($config); 

/*Change the following line*/ 

$result = $this->bmodel->getAllBanners($perPage,$this->uri->segment(5)); 


    $data['result'] = $result; 
+0

我試過了......但仍然存在錯誤。過去的幾個小時我一直在想這個。 – 2011-05-27 13:18:41

+0

嗨,當你點擊其他頁面時,url的外觀如何?是不是像「index.php /模塊/橫幅/索引/ 3」? – royrui 2011-05-27 13:24:21

+0

是的,它看起來像你在以前的評論中發佈的 – 2011-05-27 13:28:33

-1
$config['uri_segment'] = num; /* where num is the uri segment where you have page number */ 
0
$this->load->library('pagination'); 
$config['base_url']="http://localhost/CodeIgniter/pagination"; 

$config['per_page']=2; 

$config['total_rows']= $this->db->get('record')->num_rows(); 
$this->pagination->initialize($config); 
$data['query']= $this->db->get('record',$config['per_page'], $this->uri->segment(3)); 
$this->load->view('pagination',$data); 
-1

Try this,它可能會有所幫助。

class Admin_model extends CI_Model { 

public function __construct() { 
    parent::__construct(); 
} 
public function get_product($search, $page, $perpage) { 
    $page = $page - 1; 
    $page < 0 ? $page = 0 : $page = $page; 
    $from = $page * $perpage; 
    $query = $this->db 
      ->select('*') 
      ->from('tbl_product') 
      ->limit($perpage, $from) 
      ->get(); 
    return $query->result(); 
} 
}