load->library('pagination'); $pe...">

CodeIgniter routes and pagination add "/ page /" to all links

Ive implemented pagination as follows:

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

Im also uses 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 Im is facing is that although pagination works fine when I go to the second page or any other page after clicking on the pagination links - all my other links on the page allow me to add /page/forward ones like → /page/detail/aaaaaa, so my route $route["news/detail/(:any)"] = "news/news_detail/$1";cannot identify it as a detailed link.

Why is it added /page/to all links? Do I need pagination routes?

+3
source share
2 answers

$config['base_url'] $config['base_url'], /page .

, , , $config['base_url'].

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

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

Source: https://habr.com/ru/post/1787661/


All Articles