2013-03-19 39 views
1

我有一個問題Codeigniter與分段分頁。我需要傳遞頁碼。如何在分段中使用codeigniter分頁?

例子:http://www.mysite.com/app/controller/method/param1/param2/page_number

<?php 

$this->load->library('pagination'); 
$config['base_url'] = 'http://localhost/welcome/par1/para2/'; 
$config['total_rows'] = 200; 
$config['per_page'] = 20; 

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

echo $this->pagination->create_links(); 

?> 
+0

base_url總是相同或每次你需要當前頁面的url? – safarov 2013-03-19 19:09:53

+1

那些參數是動態的嗎?或總是2? – 2013-03-19 20:21:40

+0

動態,所以我有問題。 – RaviSankar 2013-03-20 06:09:39

回答

0

嘗試使用URL輔助函數current_url()作爲自己的基本網址。

從CI文檔(http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html):

current_url() - 返回頁面的完整URL(包括段)當前正在觀看。

所以,在你的情況,控制器應該是這樣的:

$this->load->library('pagination'); 
$config['base_url'] = current_url(); 
$config['total_rows'] = 200; 
$config['per_page'] = 20; 

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

echo $this->pagination->create_links(); 

這個方法應該允許您根據需要有儘可能多的參數。