0

嗨,如何在代码点火器 php 上添加可选参数以进行路由

$route['api/v1/(:any)'] = "$1/index";

$route['api/v1/(:any)/(:any)'] = "$1/index/$2";

网址例如:

app.domain.com/api/v1/users 调用$users->index()

app.domain.com/api/v1/users/1 调用$users->index(1)

我需要 tge 路线是动态的$route['api/v1/(:any)']

4

1 回答 1

0

我需要“用户”可以是动态的。我已经创建了一条路线,它对我有用,你能检查一下这是否是最好的方法。

$route['api/v1/(:any)/([a-z 0-9~%.:@_\-]+)/(:any)'] = "$1/index/$2/$3";

$route['api/v1/(:any)/(:num)'] = "$1/index/$2";

$route['api/v1/(:any)'] = "$1/index";

谢谢

于 2013-10-29T11:07:57.953 回答