Saturday, 31 August 2013

SLIM Optional Parameter Issue

SLIM Optional Parameter Issue

I trying to achieve something like this in Slim PHP:
page/p1/p2/p3/p4
I want that If I leave out params from the right(obviously) then I want to
do my stuff based on whatever params I've received.
$app->get('/page(/)(:p1/?)(:p2/?)(:p3/?)(:p4/?)',
function ($p1 = null, $p2 = null, $p3 = null, $p4 = null) {
print empty($p1)? : '' . "p1: $p1/<br/>";
print empty($p2)? : '' . "p2: $p2/<br/>";
print empty($p3)? : '' . "p3: $p3/<br/>";
print empty($p4)? : '' . "id: $p4<br/>";
});
Everything works as expected but the problem is whenever i remove a param
from the end, it prints 1 for every param I remove. why is it doing so?
what am I doing wrong here?

No comments:

Post a Comment