Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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...



81.3k
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}