re-route with optional argument. possible bug?? |
hello there,
so i was working a project and tried to make an obvious route that did not work. Example if you have a route like PHP Code: $route["admin/foos/(:num)"] = "admin/hello/$1"; PHP Code: public function hello($arg=null) { Code: is NULL 2. calling url http://localhost/<project>/admin/foos/547 is as expected Code: has 547 If I remove the route like PHP Code: // $route["admin/foos/(:num)"] = "admin/hello/$1"; the result is as expected Code: is NULL PHP Code: has 586 The workaround i found was PHP Code: $route["admin/foos/?(:num)?"] = "admin/hello/$1";
Harpreet Bhatia
Web Developer / Analyst Technical Reviewer - "Codeigniter 2 Cookbook"
Well i will leave it to smarter people then me whether this is a "bug" or not. But for me it is exactly what i would expect. If i'm assigning a route, and that route is supposed to have a number, then if the url does not have a number it should be a 404.
If however its a case of - it could have a number - or not - then assign a route for the other case. Then it will work for either condition: PHP Code: $route["admin/foos/(:num)"] = "admin/hello/$1"; (06-08-2016, 01:43 PM)cartalot Wrote: Well i will leave it to smarter people then me whether this is a "bug" or not. But for me it is exactly what i would expect. If i'm assigning a route, and that route is supposed to have a number, then if the url does not have a number it should be a 404. yes this too can work. agreed. But i would like to know if what i reported can be done.
Harpreet Bhatia
Web Developer / Analyst Technical Reviewer - "Codeigniter 2 Cookbook"
http://localhost/<project>admin/foos does link to $route ["admin/foos" ] = "admin/hello" ;(which is not define in route) and i think will not link to
$route ["admin/foos/(:num)" ] = "administered/hello/$1" ;
Keep calm.
$route ["admin/foos" ] = "admin/hello" ; is not define. http://localhost/<project>admin/foos and http://localhost/<project>admin/foos/bars is different.
Keep calm.
(06-09-2016, 01:09 AM)arma7x Wrote: http://localhost/<project>admin/foos does link to $route ["admin/foos" ] = "admin/hello" ;(which is not define in route) and i think will not link to The problem is that even though the parameter is optional, the route PHP Code: $route["admin/foos/(:num)"] = "admin/hello/$1"; PHP Code: $route["admin/hello/(:num)"] = "admin/hello/$1"; Code: http://localhost/<project>admin/foos Code: http://localhost/<project>admin/hello
Harpreet Bhatia
Web Developer / Analyst Technical Reviewer - "Codeigniter 2 Cookbook"
The parameter in your rule is not optional. You need to do what cartalot suggested in the first reply to your post.
|
Welcome Guest, Not a member yet? Register Sign In |