Project Versions

Table Of Contents

Previous topic

Class Phalcon\Mvc\Model\Validator\Uniqueness

Next topic

Class Phalcon\Mvc\Router\Exception

This Page

Class Phalcon\Mvc\Router

implements Phalcon\Mvc\RouterInterface, Phalcon\DI\InjectionAwareInterface

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

<?php

$router = new Phalcon\Mvc\Router();
$router->handle();
echo $router->getControllerName();

Methods

public __construct (boolean $defaultRoutes)

Phalcon\Mvc\Router constructor

public setDI (Phalcon\DiInterface $dependencyInjector)

Sets the dependency injector

public Phalcon\DiInterface getDI ()

Returns the internal dependency injector

protected string _getRewriteUri ()

Get rewrite info

public setDefaultNamespace (string $namespaceName)

Sets the name of the default namespace

public setDefaultModule (string $moduleName)

Sets the name of the default module

public setDefaultController (string $controllerName)

Sets the default controller name

public setDefaultAction (string $actionName)

Sets the default action name

public setDefaults (array $defaults)

Sets an array of default paths

public handle (string $uri)

Handles routing information received from the rewrite engine

public Phalcon\Mvc\Router\Route add (string $pattern, string/array $paths, string $httpMethods)

Adds a route to the router on any HTTP method

public Phalcon\Mvc\Router\Route addGet (string $pattern, string/array $paths)

Adds a route to the router that only match if the HTTP method is GET

public Phalcon\Mvc\Router\Route addPost (string $pattern, string/array $paths)

Adds a route to the router that only match if the HTTP method is POST

public Phalcon\Mvc\Router\Route addPut (string $pattern, string/array $paths)

Adds a route to the router that only match if the HTTP method is PUT

public Phalcon\Mvc\Router\Route addDelete (string $pattern, string/array $paths)

Adds a route to the router that only match if the HTTP method is DELETE

public Phalcon\Mvc\Router\Route addOptions (string $pattern, string/array $paths)

Add a route to the router that only match if the HTTP method is OPTIONS

public Phalcon\Mvc\Router\Route addHead (string $pattern, string/array $paths)

Adds a route to the router that only match if the HTTP method is HEAD

public clear ()

Removes all the pre-defined routes

public string getNamespaceName ()

Returns processed namespace name

public string getModuleName ()

Returns processed module name

public string getControllerName ()

Returns processed controller name

public string getActionName ()

Returns processed action name

public array getParams ()

Returns processed extra params

public Phalcon\Mvc\Router\Route getMatchedRoute ()

Returns the route that matchs the handled URI

public array getMatches ()

Return the sub expressions in the regular expression matched

public bool wasMatched ()

Check if the router macthes any of the defined routes

public Phalcon\Mvc\Router\Route [] getRoutes ()

Return all the routes defined in the router

public Phalcon\Mvc\Router\Route getRouteById (unknown $id)

Returns a route object by its id

public Phalcon\Mvc\Router\Route getRouteByName (unknown $name)

Returns a route object by its name