Codeigniter分页URL问题

时间:2011-12-28 17:09:05

标签: codeigniter

我刚刚在我的网站www.reviewongadgets.com

中实施了分页

当我点击主页时,它被分为两个页面,这是正确的,但当我点击下一个链接时,它显示的URL为

http://www.reviewongadgets.com/home/10 

这也是正确的,但是当我回到上一页编号时,它将URL显示为

http://www.reviewongadgets.com/home/home/

那么请帮忙解决这个问题?以下是$urlhttp://www.reviewongadgets.com/home

的控制器代码段
$config['base_url'] = $url;
$config['total_rows'] = $this->MiscellaneousModel->countEntries();
$config['per_page'] = 10; 
$base_url = site_url('/');
$config['uri_segment'] = '2';
//$config['page_query_string'] = TRUE;
$this->pagination->initialize($config); 

2 个答案:

答案 0 :(得分:1)

这应该适合你(着名的遗言)

//Add this to your routes
$route['home/(:num)'] = 'home/index/$1';


public function index($offset=0){

$limit = $this->config->item('pagination_per_page'); // default 10

//find data based on limits and offset
$query = //you query LIMIT = $limit OFFSET = $offset

$count = //count the number of rows returned by $query

//init pagination attributes
$config = array(
        'base_url' => site_url('home'),
        'total_rows' => $count,
        'per_page' => $limit,
        'uri_segment' => 2
    );
$this->pagination->initialize($config); 

//load the view and pagination data
$this->load->view('some_view', array(
        'pagination'  =>  $this->pagination->create_links(),
        'data'  => //data return from $query as object or array
));
}

答案 1 :(得分:0)

问题可能出在你如何定义base_url上,因为你给它一个变量,但你没有告诉你在哪里以及如何为它赋值。试试:

$config['base_url'] = site_url('home');
$config['total_rows'] = $this->MiscellaneousModel->countEntries();
$config['per_page'] = 10; 
$config['uri_segment'] = '2';

由于您正在使用索引方法,因此可能指定它可以解决问题(我曾经遇到类似的问题而且确实有效)

$config['base_url'] = site_url('home/index');