Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
This will match:
$url = Router::match(array('controller' => 'users', 'action' => 'login'));
returns /login
For URLs templates with no insert parameters (i.e. elements like {:id} that are replaced
with a value), all parameters must match exactly as they appear in the route parameters.
Alternatively to using a full array, you can specify routes using a more compact syntax. The
above example can be written as:
$url = Router::match('Users::login'); // still returns /login
You can combine this with more complicated routes; for example:
Router::connect('/posts/{:id:\d+}', array('controller' => 'posts', 'action' => 'view'));
This will match:
$url = Router::match(array('controller' => 'posts', 'action' => 'view', 'id' => '1138'));
returns /posts/1138
Again, you can specify the same URL with a more compact syntax, as in the following:
$url = Router::match(array('Posts::view', 'id' => '1138'));
again, returns /posts/1138
You can use either syntax anywhere an URL is accepted, i.e. when redirecting
or creating links using the Html helper.