Routing is the main part to any application. Tomahawk makes use of Symfony's poweful Routing Component, as there's no point re-inventing the wheel. You can read more about Symfony Routing here.

Defining Routes

You add routes in the app/Resources/routes.php file.

You define routes using the Tomahawk\Routing\Router class. There should be one instantiated in this file already.

From the example above, the 1st parameter is the path, the 2nd is the name of the route (used by the URL Generator) and the 3rd is the callback.

1.4 introduced short notation and service notation for a callback

A callback can be either a closure or string defining the class and method in the following formats

Controller::Action Notation MyBundle\Controllers\UserController::homeAction

service:action Notation user.controller::homeAction

Important - Service Notation expects your service to have a dot in.

Short Bundle Notation UserBundle:User:home which would get converted to UserBundle\Controller\UserController::homeAction

Important - Short Bundle Notation expects your controllers to be within a folder called Controller in your bundle. The Controller name also needs to end with Controller e.g UserController.
The action name in the Controller class should also end with action. e.g. homeAction.

Route Parameters

You can define parameters to capture in the URL.

You can also set a default value:

Declaring parameter constraints:

You can also have the Request passed in to the callback:

Route Sections

You can also define a section to control a group of routes.

You can also pass in a set of default parameters to be used by the request, useful for defining routes that require auth for example.