< Class Phalcon\Cli\Dispatcher\Exception


Class Phalcon\Cli\Router\Exception >


Class Phalcon\Cli\Router

implements Phalcon\Di\InjectionAwareInterface

Source on GitHub

Phalcon\Cli\Router is the standard framework router. Routing is the process of taking a command-line arguments and decomposing it into parameters to determine which module, task, and action of that task should receive the request


$router = new \Phalcon\Cli\Router();
    'module' => 'main',
    'task' => 'videos',
    'action' => 'process'
echo $router->getTaskName();


public __construct ([unknown $defaultRoutes])

Phalcon\Cli\Router constructor

public setDI (Phalcon\DiInterface $dependencyInjector)

Sets the dependency injector

public getDI ()

Returns the internal dependency injector

public setDefaultModule (unknown $moduleName)

Sets the name of the default module

public setDefaultTask (unknown $taskName)

Sets the default controller name

public setDefaultAction (unknown $actionName)

Sets the default action name

public setDefaults (array $defaults)

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


    'module' => 'common',
    'action' => 'index'

public handle ([array $arguments])

Handles routing information received from command-line arguments

public Phalcon\Cli\Router\Route add (string $pattern, [string/array $paths])

Adds a route to the router


 $router->add('/about', 'About::main');

public getModuleName ()

Returns proccesed module name

public getTaskName ()

Returns proccesed task name

public getActionName ()

Returns proccesed action name

public array getParams ()

Returns proccesed extra params

public getMatchedRoute ()

Returns the route that matchs the handled URI

public array getMatches ()

Returns the sub expressions in the regular expression matched

public wasMatched ()

Checks if the router macthes any of the defined routes

public getRoutes ()

Returns all the routes defined in the router

public Phalcon\Cli\Router\Route getRouteById (int $id)

Returns a route object by its id

public getRouteByName (unknown $name)

Returns a route object by its name

Follow along: