Class Phalcon\Mvc\Router\Route

implements Phalcon\Mvc\Router\RouteInterface

Source on GitHub

This class represents every route added to the router

Methods

public __construct (mixed $pattern, [mixed $paths], [mixed $httpMethods])

Phalcon\Mvc\Router\Route constructor

public compilePattern (mixed $pattern)

Replaces placeholders from pattern returning a valid PCRE regular expression

public via (mixed $httpMethods)

Set one or more HTTP methods that constraint the matching of the route

  1. <?php
  2. $route->via("GET");
  3. $route->via(
  4. [
  5. "GET",
  6. "POST",
  7. ]
  8. );

public extractNamedParams (mixed $pattern)

Extracts parameters from a string

public reConfigure (mixed $pattern, [mixed $paths])

Reconfigure the route adding a new pattern and a set of paths

public static getRoutePaths ([mixed $paths])

Returns routePaths

public getName ()

Returns the route’s name

public setName (mixed $name)

Sets the route’s name

  1. <?php
  2. $router->add(
  3. "/about",
  4. [
  5. "controller" => "about",
  6. ]
  7. )->setName("about");

public beforeMatch (mixed $callback)

Sets a callback that is called if the route is matched. The developer can implement any arbitrary conditions here If the callback returns false the route is treated as not matched

  1. <?php
  2. $router->add(
  3. "/login",
  4. [
  5. "module" => "admin",
  6. "controller" => "session",
  7. ]
  8. )->beforeMatch(
  9. function ($uri, $route) {
  10. // Check if the request was made with Ajax
  11. if ($_SERVER["HTTP_X_REQUESTED_WITH"] === "xmlhttprequest") {
  12. return false;
  13. }
  14. return true;
  15. }
  16. );

public getBeforeMatch ()

Returns the ‘before match’ callback if any

public match (mixed $callback)

Allows to set a callback to handle the request directly in the route

  1. <?php
  2. $router->add(
  3. "/help",
  4. []
  5. )->match(
  6. function () {
  7. return $this->getResponse()->redirect("https://support.google.com/", true);
  8. }
  9. );

public getMatch ()

Returns the ‘match’ callback if any

public getRouteId ()

Returns the route’s id

public getPattern ()

Returns the route’s pattern

public getCompiledPattern ()

Returns the route’s compiled pattern

public getPaths ()

Returns the paths

public getReversedPaths ()

Returns the paths using positions as keys and names as values

public setHttpMethods (mixed $httpMethods)

Sets a set of HTTP methods that constraint the matching of the route (alias of via)

  1. <?php
  2. $route->setHttpMethods("GET");
  3. $route->setHttpMethods(["GET", "POST"]);

public getHttpMethods ()

Returns the HTTP methods that constraint matching the route

public setHostname (mixed $hostname)

Sets a hostname restriction to the route

  1. <?php
  2. $route->setHostname("localhost");

public getHostname ()

Returns the hostname restriction if any

public setGroup (Phalcon\Mvc\Router\GroupInterface $group)

Sets the group associated with the route

public getGroup ()

Returns the group associated with the route

public convert (mixed $name, mixed $converter)

Adds a converter to perform an additional transformation for certain parameter

public getConverters ()

Returns the router converter

public static reset ()

Resets the internal route id generator