I tried many ways to solve this problem but none works.
suppose I have a class:
class MyTestClass{
function testPrint($a = '', $b = '', $c = '')
{
echo '1: ' . $a . ', 2: ' . $b . ', 3: ' . $c;
}
}
and if I access this function by using this url
http://localhost/ci/index.php/myTestClass/testPrint/a/b/c you will see 1: a, 2: b, 3: c as output, it’s fine.
But if I assign $b to an empty string, the url will change to http://localhost/ci/index.php/myTestClass/testPrint/a//c
The output will change to 1: a, 2: c, 3: It seems CI ignores the missing parameter.
Question is how to prevent CI ignoring the missing parameter in the middle of uri?
My expected output for just now the url is 1: a, 2: , 3: c
Btw, I tried to use $this->uri->segment(n) to secure the parameter position, but it doesn’t work.
I tried to update the routes.php by adding:
$route['myTestClass/(:any)/(:any)/(:any)/(:any)'] = "myTestClass/$1/$2/$3/$4"; but this does not change anything.
Any idea?
I’m not sure if this is possible in your case, but what I would do is use a short dummy string (xyz in this example) just to prevent having to deal with
/ /and then filtering it out.http://localhost/ci/index.php/myTestClass/testPrint/a/xyz/cIf it’s possible, try POST-ing variables instead of using the URI segments. That would make things a lot easier.
Hope this helps.
Update:
Since you can’t POST, how about enabling query strings?