1.一对一:uri字符串唯一对应控制器(controller)类/方法
example.com/class/function/id
2.一对多:
uri字符串重定向调用一个不同的类/方法(class/function)
example.com/product/1/
example.com/product/2/
example.com/product/3/
example.com/product/4/
3.自定义路由规则
CI路由从上到下读取路由
规则,自定义路由规则方法:
(1)通配符
$route['(:any)'] = 'pages/view/$1';
:any 匹配任何字符
:num 匹配一个数字
(2)正则表达式
$route['news/([a-z]+)/(\d+)'] = "\\1/id_\\2";
example.com/news/id/1-------> example.com/news/id_1
example.com/news/id/2-------> example.com/news/id_2
example.com/news/id/3-------> example.com/news/id_3
4.保留路由
$route['default_controller'] = 'welcome'; 默认Welcome controller的index方法
$route['404_override'] = ''; 覆盖了默认的404错误页面application/errors/error_404.php,需要自定义
阅读(1863) | 评论(0) | 转发(0) |