use*_*396 3 php url codeigniter
我试图将参数传递给CodeIgniter上的控制器,但我希望网址是这样的:
mywebsite/profile/{user_id}/about
Run Code Online (Sandbox Code Playgroud)
而不是这样的:
mywebsite/profile/about/{user_id}
Run Code Online (Sandbox Code Playgroud)
所以有可能吗?我们怎么做呢?
这对我有用,我刚试过它:
在routes.php中创建一个新路由,如下所示:
$route['profile/(:any)/about'] = 'profile/about/$1';
Run Code Online (Sandbox Code Playgroud)
这将重写URL,例如"yoursite.com/profile/about/23"到"yoursite.com/profile/23/about".我假设,"profile"是你的控制器,"about"就是这个功能.
希望这可以帮助!但是,没有使用来自数据库的ID测试它.