CodeIgniter中的路由+分页 - 无法打开第一页

时间:2012-08-23 12:04:05

标签: codeigniter pagination

我定义了这条路线:

$route['search/(:any)/(:num)/(:num)/(:num)/(:num)'] = "home/results/$1/$2/$3/$4/$5";

和我在results()函数中的分页:

    $config['base_url'] = base_url().'/search/'.$data['keyword'].'/'.$data['1'].'/'.$data['2'].'/'.$data['3'].'/';
    $config['per_page'] = 10;
    $config['uri_segment']=6; 

它的效果非常好,但是当我从任何下一页回到第一页时 - 找不到网址,因为当我在浏览器中输入时:

mysite.com/search/key/param1/param2/param3/0 (first page) -> works fine

但是当我想从第一页开始:

mysite.com/search/key/param1/param2/param3/10 (second page) => 
mysite.com/search/key/param1/param2/param3/ (fiest page - without "0" index at the end, pagination doesn't add it at the end)

然后找不到网址

1 个答案:

答案 0 :(得分:0)

你必须添加多条路线才能工作:

$route['search/(:any)/(:num)/(:num)/(:num)/(:num)'] = "home/results/$1/$2/$3/$4/$5";
$route['search/(:any)/(:num)/(:num)/(:num)'] = "home/results/$1/$2/$3/$4/0";
$route['search/(:any)/(:num)/(:num)'] = "home/results/$1/$2/$3/0/0";
...

我认为你收到了消息