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

Route with many parameters

Hi the syntax for the route is $router->add( "/admin/:controller/a/:action/:params", [ "controller" => 1, "action" => 2, "params" => 3, ] );

what if I have many parameters lets say I want a post($id,$name,$surname), can someone give me an example of route that can take this post and being reusable for a similar post but with different attributes like post($id,$accountName,$type). Thanks in advance.

Hey, you have two options:

1) Define all possible routes like:

/blabla/:id/:username/:type
/blabla/:id/:username
/blabla/:id

2) Or just use the :params parameter at the end of the route:

// Definition
/blabla/:params

// Call it like:
$params = [123, 456, 789];
$this->url->get(['for' => 'blabla', 'params' => implode('/', $params)]);

// Output
/blabla/123/456/789

// Get params values in controller
print_r($this->dispatcher->getParams());


7.0k
edited Dec '16

$router->add('/movies/{movie:[0-9]+}/deleteTag/{tag:[0-9]+}','movies::deleteTag');