implements Phalcon\Di\InjectionAwareInterface, Phalcon\Mvc\RouterInterface, Phalcon\Events\EventsAwareInterface
Phalcon\Mvc\Router is the standard framework router. Routing is the process of taking a URI endpoint (that part of the URI which comes after the base URL) and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request
use Phalcon\Mvc\Router; $router = new Router(); $router->add( '/documentation/{chapter}/{name}\.{type:[a-z]+}', [ 'controller' => 'documentation', 'action' => 'show' ) ); $router->handle(); echo $router->getControllerName();
Phalcon\Mvc\Router constructor
Sets the dependency injector
Returns the internal dependency injector
Sets the events manager
Returns the internal event manager
Get rewrite info. This info is read from $_GET[‘_url’]. This returns ‘/’ if the rewrite information cannot be read
Sets the URI source. One of the URI_SOURCE_* constants
$router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI);
Set whether router must remove the extra slashes in the handled routes
Sets the name of the default namespace
Sets the name of the default module
Sets the default controller name
Sets the default action name
Sets an array of default paths. If a route is missing a path the router will use the defined here This method must not be used to set a 404 route
$router->setDefaults([ 'module' => 'common', 'action' => 'index' ]);
Returns an array of default parameters
Handles routing information received from the rewrite engine
// Read the info from the rewrite engine $router->handle(); // Manually passing an URL $router->handle('/posts/edit/1');
Adds a route to the router without any HTTP constraint
use Phalcon\Mvc\Router; $router->add('/about', 'About::index'); $router->add('/about', 'About::index', ['GET', 'POST']); $router->add('/about', 'About::index', ['GET', 'POST'], Router::POSITION_FIRST);
Adds a route to the router that only match if the HTTP method is GET
Adds a route to the router that only match if the HTTP method is POST
Adds a route to the router that only match if the HTTP method is PUT
Adds a route to the router that only match if the HTTP method is PATCH
Adds a route to the router that only match if the HTTP method is DELETE
Add a route to the router that only match if the HTTP method is OPTIONS
Adds a route to the router that only match if the HTTP method is HEAD
Adds a route to the router that only match if the HTTP method is PURGE (Squid and Varnish support)
Adds a route to the router that only match if the HTTP method is TRACE
Adds a route to the router that only match if the HTTP method is CONNECT
Mounts a group of routes in the router
Set a group of paths to be returned when none of the defined routes are matched
Removes all the pre-defined routes
Returns the processed namespace name
Returns the processed module name
Returns the processed controller name
Returns the processed action name
Returns the processed parameters
Returns the route that matches the handled URI
Returns the sub expressions in the regular expression matched
Checks if the router matches any of the defined routes
Returns all the routes defined in the router
Returns a route object by its id
Returns a route object by its name
Returns whether controller name should not be mangled
© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Router.html