我试图将参数传递给 CodeIgniter 上的 Controller ,但我希望 url 是这样的:
mywebsite/profile/{user_id}/about
不是这样的:
mywebsite/profile/about/{user_id}
所以有可能吗?我们该怎么做?
最佳答案
这对我有用,我刚刚测试过:
在 routes.php 中创建一个新路由,如下所示:
$route['profile/(:any)/about'] = 'profile/about/$1';
这将重写 URL,例如“yoursite.com/profile/about/23”到“yoursite.com/profile/23/about”。我假设“配置文件”是您的 Controller ,“关于”是功能。
希望这对您有所帮助!不过,没有使用来自数据库的 ID 对其进行测试。
关于php - codeigniter 在 url 中的方法之前传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16524455/