Typically, Route objects are created and handled through the Router class, as follows.
When connecting a route, a Route object is instantiated behind the scenes, and added
to the Router's collection.
Router::connect("/{:controller}/{:action}");
This following matches a set of parameters against all Route objects contained in Router, and
if a match is found, returns a string URL with parameters inserted into the URL pattern.
Router::match(array("controller" => "users", "action" => "login")); // returns "/users/login"
For more advanced routing, however, you can directly instantiate a Route object, a subclass,
or any class that implements parse() and match() (see the documentation for each individual
method) and configure it manually -- if, for example, you want the route to match different
incoming URLs than it generates.
$route = new Route(array(
'template' => '/users/{:user}',
'pattern' => '@^/u(?:sers)?(?:/(?P[^\/]+))$@',
'params' => array('controller' => 'users', 'action' => 'index'),
'match' => array('controller' => 'users', 'action' => 'index'),
'defaults' => array('controller' => 'users'),
'keys' => array('user' => 'user'),
'options' => array('compile' => false, 'wrap' => false)
));
Router::connect($route); // this will match '/users/' or '/u/'.