A free and open-source book on ZF3 for beginners


5.2. Route Types

Routing is a mechanism which allows to map HTTP request to a controller's action. With routing, ZF3 knows which of the controller's action method to execute as the result of the request. For example, you can map "http://localhost/" URL to IndexController::indexAction() method, and "http://localhost/about" URL to IndexController::aboutAction() method.

You define the mapping between URLs and controllers with the help of routes.

There are several standard route types provided by Zend Framework 3 (shown in table 5.1). These route types are implemented as classes living in the Zend\Router\Http namespace.

Table 5.1. Route Types
Route Type Description
Literal Exact matching against the path part of a URL.
Segment Matching against a path segment (or several segments) of a URL.
Regex Matching the path part of a URL against a regular expression template.
Hostname Matching the host name against some criteria.
Scheme Matching URL scheme against some criteria.
Method Matching an HTTP method (e.g. GET, POST, etc.) against some criteria.

Each route type in the table above (except the Method type) may be matched against a specific part (or several parts) of a URL. The Method route type is matched against the HTTP method (either GET or POST) retrieved from HTTP request.


Top