We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Router string parameter for search controller

I am creating a generic search for my app and am trying to use "router" to generate something like "/search/anything+here" I'm doing it this way:

$di->set('router', function(){
  $router = new \Phalcon\Mvc\Router();
      "controller" => "search",
      "action"  => "search",

  return $router;

In SearchController I try this

    public function searchAction()
      $term = $this->dispatcher->getParam("term");

Thus I can only get the parameter {term} if only with a simple word like "anything" if I use "anything+here" or "anything here" the router is ignored.

I do not know if I was clear on the issue.

Your route definition is not accepting white spaces, so it will not be matched.

Repair your regular expression for this route to include characters you want to put in search term.


Little addition to David's comment.

More info and list of examples(regular expressions) here: https://docs.phalcon.io/en/latest/reference/routing.html

Or you can just omit the regular expression in the route and allow the user to search freely :