We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Optional param in Phalcon Router

Hi,

Im trying to make a param in one of my routes optional

something like /movie/detail/{id}/{name}/{importFlag}

the importFlag is optional...



98.9k
Accepted
answer

You can define two routes:

$router->add(
    "/movie/detail/{id}/{name}/{importFlag}",
    array(
        "controller" => "movies",
        "action"     => "getDetails",
    )
);

$router->add(
    "/movie/detail/{id}/{name}",
    array(
        "controller" => "movies",
        "action"     => "getDetails",
    )
);
edited Oct '15

Hi Phalcon, do you mean we cannot use regex? Like

For example:

detail[/]{0,1}{importFlag}