使用codeigniter路由来省略uri的一部分


Using codeigniter routes to leave out a part of the uri

我有这个uri http://localhost/ur/index.php/reports/annual/gm/8312/44724286729,但annual部分的作用是向用户显示他/她正在查看的报告。

因此被映射的函数是具有参数的gm

public function gm($id,$telephone_number{
/**
General Meeting
*/
}

http://localhost/ur/index.php/reports/annual/gm/8312/44724286729

我的控制器文件名为reports。我如何使用路由来忽略annual,而只使用gm作为我的函数和uri的其他部分作为我的参数,即8312/44724286729?。

我在routes 中尝试过

$route['annual/(:any)'] = "gm";

您可以尝试使用美元符号语法作为

$route['reports/annual/(:any)/(:any)'] = "reports/gm/$1/$2";

reports控制器中,gm函数将使用$1 and $2作为参数。

附言:请参阅CI手册中的URI路由部分。