Welcome Guest, Not a member yet? Register   Sign In
re-route with optional argument. possible bug??
#1

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"
and a function in admin controller as
PHP Code:
public function hello($arg=null) {
        if(empty(
$arg)){
            echo 
"is NULL";
        }
        else{
            echo 
"has $arg";
        }
    } 
1. The expected result on calling http://localhost/<project>admin/foos should be  (but is 404)
Code:
is NULL

2. calling url http://localhost/<project>/admin/foos/547 is as expected

Code:
has 547
Unexpectedly case 1 does not work, its lands to native CI 404 page. This only happens when you are making a route.
If I remove the route like
PHP Code:
// $route["admin/foos/(:num)"] = "admin/hello/$1"; 
and call url direclty  as http://localhost/<project>/admin/hello
the result is as expected
Code:
is NULL
http://localhost/<project>/admin/hello/586 is
PHP Code:
has 586 

The workaround i found was
PHP Code:
$route["admin/foos/?(:num)?"] = "admin/hello/$1"
Any help is appreciated.
Harpreet Bhatia
Web Developer / Analyst
Technical Reviewer - "Codeigniter 2 Cookbook"

Reply


Messages In This Thread
re-route with optional argument. possible bug?? - by harpreet - 06-07-2016, 10:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB