开发者

CodeIgniter routes and pagination adding “/page/” to all links

I’ve implemented pagination like the following:

$this->load->library('pagination');

$perpage=10;
$config['base_url'] = site_url().'news/page';
$config['total_rows'] = $this->news_model->getnews(array('count' => true));
$config['per_page'] = $perpage;
$config['uri_segment'] = 3;
$config['num_links'] = 8;

$news = $this->news_model->getnews(array('limit' => $perpage,'offset'=>$offset));

$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_开发者_如何学Golinks();

$data['news'] = $news;
$data['page'] = "news";

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

I’m also using the following routes:

$route["news"] = "news/news_list";
$route["news/page"] = "news/news_list";
$route["news/page/(:num)"] = "news/news_list/$1";
$route["news/detail/(:any)"] = "news/news_detail/$1";

The problem that I’m facing is that although the pagination is working fine when i go to the second page or any other page after clicking on the pagination links - all of my other links on the page get the /page/ added in front of them like -> /page/detail/aaaaaa so that my route $route["news/detail/(:any)"] = "news/news_detail/$1"; can not identify it as the detail link.

Why is the /page/ added to all of the links? Do i need any routes for Pagination?


Your $config['base_url'] is news/page, that’s why /page is added to all your links.

I don’t think you need these routes for pagination, but if you want them, you should use these routes in $config['base_url'].


$route["news/page/(:num)"] = "news/news_list/$2";

$route["news/detail/(:any)"] = "news/news_detail/$1";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜