Codeigniter Routing Unlimited Paramaters

后端 未结 3 1031
感情败类
感情败类 2021-01-15 02:49

I currently have this in my CodeIgniter routes file. It maps anything with a URI api/controller/function to controller/api_function.



        
相关标签:
3条回答
  • 2021-01-15 03:34

    I believe just this would do:

    $route['api/(:any)/(:any)'] = '$1/api_$2';
    $route['api/(:any)/(:any)/(:any)'] = '$1/api_$2/$3';
    
    0 讨论(0)
  • 2021-01-15 03:47

    Try this:

    $route['api/([^/]*)/([^/]*)/(.*)'] = '$1/api_$2/$3';
    

    It basically checks for two segments (any character but a slash), then anything after that gets appended as parameters to your controller function.

    This wouldn't match for routes with NO parameters, but it's not hard to do if that's a case you need to handle.

    0 讨论(0)
  • 2021-01-15 03:52

    This Works perfectly,

    $route['api/(.*)']='api/$1';
    
    0 讨论(0)
提交回复
热议问题