Router

Routing (MVC & CLI)

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

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.

Configurations

# mvc default routes
ROUTER_DEFAULT_NAMESPACE=Zemit\Modules\Frontend\Controllers
ROUTER_DEFAULT_MODULE=frontend
ROUTER_DEFAULT_CONTROLLER=index
ROUTER_DEFAULT_ACTION=index

# cli default routes
ROUTER_CLI_DEFAULT_NAMESPACE=Zemit\Modules\Cli\Tasks
ROUTER_CLI_DEFAULT_MODULE=cli
ROUTER_CLI_DEFAULT_TASK=help
ROUTER_CLI_DEFAULT_ACTION=main

# not-found
ROUTER_NOTFOUND_NAMESPACE=
ROUTER_NOTFOUND_MODULE=
ROUTER_NOTFOUND_CONTROLLER=error
ROUTER_NOTFOUND_TASK=error
ROUTER_NOTFOUND_ACTION=notFound

# fatal
ROUTER_FATAL_NAMESPACE=
ROUTER_FATAL_MODULE=
ROUTER_FATAL_CONTROLLER=error
ROUTER_FATAL_TASK=error
ROUTER_FATAL_ACTION=fatal

# forbidden
ROUTER_FORBIDDEN_NAMESPACE=
ROUTER_FORBIDDEN_MODULE=
ROUTER_FORBIDDEN_CONTROLLER=error
ROUTER_FORBIDDEN_TASK=error
ROUTER_FORBIDDEN_ACTION=forbidden

# unauthorized
ROUTER_UNAUTHORIZED_NAMESPACE=
ROUTER_UNAUTHORIZED_MODULE=
ROUTER_UNAUTHORIZED_CONTROLLER=error
ROUTER_UNAUTHORIZED_TASK=error
ROUTER_UNAUTHORIZED_ACTION=unauthorized

# default maintenance
ROUTER_MAINTENANCE_NAMESPACE=
ROUTER_MAINTENANCE_MODULE=
ROUTER_MAINTENANCE_CONTROLLER=error
ROUTER_MAINTENANCE_TASK=error
ROUTER_MAINTENANCE_ACTION=maintenance

# error
ROUTER_ERROR_NAMESPACE=
ROUTER_ERROR_MODULE=
ROUTER_ERROR_CONTROLLER=error
ROUTER_ERROR_TASK=error
ROUTER_ERROR_ACTION=index

# define your own service provider
PROVIDER_ROUTER=\Zemit\Provider\Router\ServiceProvider

Usage

// if the class is aware of injections
$router = $this->router;

// if the container is present
$router = $this->di->get('router');

// from outside
$router = Di::getDefault()->get('router');

Phalcon\Cli

Phalcon\Mvc

Sources

Last updated