CodeIgniter路由和分页将“/ page /”添加到所有链接

时间:2011-01-25 11:22:54

标签: codeigniter pagination routes

我已经实现了以下分页:

$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_links();

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

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

我也使用以下路线:

$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";

我面临的问题是,虽然在点击分页链接后进入第二页或任何其他页面时分页工作正常 - 但我在页面上的所有其他链接都获得了{{1}在他们面前添加像 - > /page/以便我的路线/page/detail/aaaaaa无法将其识别为详细信息链接。

为什么$route["news/detail/(:any)"] = "news/news_detail/$1";添加到所有链接中?我需要任何分页路线吗?

2 个答案:

答案 0 :(得分:2)

您的$config['base_url']news/page,这就是为什么/page被添加到您的所有链接中的原因。

我认为您不需要这些路线进行分页,但如果您需要这些路线,则应在$config['base_url']中使用这些路线。

答案 1 :(得分:0)

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

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