Codeigniter分页URL问题
我刚刚在我的网站上实现了分页 当我点击主页时,它被分为两个页面,这是正确的,但当我点击下一个链接时,它显示URL为Codeigniter分页URL问题,codeigniter,Codeigniter,我刚刚在我的网站上实现了分页 当我点击主页时,它被分为两个页面,这是正确的,但当我点击下一个链接时,它显示URL为 http://www.reviewongadgets.com/home/10 这也是正确的,但当我回到上一个页码时,它显示URL为 http://www.reviewongadgets.com/home/home/ 你能帮我解决这个问题吗?下面是控制器代码段,其中$url是http://www.reviewongadgets.com/home $config['base_ur
http://www.reviewongadgets.com/home/10
这也是正确的,但当我回到上一个页码时,它显示URL为
http://www.reviewongadgets.com/home/home/
你能帮我解决这个问题吗?下面是控制器代码段,其中$url
是http://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);
问题可能在于如何定义base_url,因为您给了它一个变量,但没有告诉它在哪里以及如何给它赋值。尝试:
$config['base_url'] = site_url('home');
$config['total_rows'] = $this->MiscellaneousModel->countEntries();
$config['per_page'] = 10;
$config['uri_segment'] = '2';
因为您使用的是index方法,也许指定它可以解决这个问题(我曾经遇到过类似的问题,而且确实有效)
这应该适合你(著名的遗言)
$config['base_url'] = site_url('home/index');
//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
));
}