我对路由有一些问题。我想从一个功能发送不同的 URL。
这是我的功能
function road($1,$2,$3){
bla bla bla
}
和 我要路线
localhost/index.php/mycontroller/road/1/2/3
自
localhost/index.php/mycontroller/road/1/2/3
如果 $3 =0.我想将其路由到
localhost/index.php/mycontroller/street/1/2/0
您可以在
函数中执行重定向road()
if($3 === 0)
redirect('mycontroller/street/'$1 . '/' . $2 . '/' . $3);
或者在config/routes.php
中设置自定义路由
$route['mycontroller/road/(:any)/(:any)/0'] = 'mycontroller/street/$1/$2/0';
编辑:加载url_helper
后,redirect()
功能可用。您可以在config/autoload.php
中执行此操作,也可以在调用函数之前添加此行:$this->load->helper('url');