The Phalcon\Mvc\Router
component allows you to define routes that are mapped to controllers or handlers that receive and can handle the request. The router has two modes: MVC mode and match-only mode. The first mode is ideal for working with MVC applications.
<?php
use Phalcon\Mvc\Router;
$router = new Router();
$router->add(
'/admin/invoices/list',
[
'controller' => 'invoices',
'action' => 'list',
]
);
$router->handle(
$_SERVER["REQUEST_URI"]
);
Constants : There are two constants available for the Phalcon\Mvc\Router
component that are used to define the position of the route in the processing stack.
POSITION_FIRST
POSITION_LAST
Methods :
public function __construct(
bool $defaultRoutes = true
)
Phalcon\Mvc\Router constructor :
public function add(
string $pattern,
mixed $paths = null,
mixed $httpMethods = null,
mixed $position = Router::POSITION_LAST
): RouteInterface