Silex-Routing allows you to define custom and multiple routers for Silex. This is especially useful when working with dynamic routes, which are not known while writing the code (e.g. URLs stored in database).
This implementation works for both, matching and generating of URLs.
The advanced routing is achieved by connecting Silex with symfony-cmf/Routing.
The recommended way to install Silex-Routing is through
composer. Just create a composer.json
file and
run the php composer.phar install
command to install it:
{
"require": {
"project-a/silex-routing": "dev-master"
}
}
Alternatively, you can download the silexrouting.zip
file and extract it.
Version 2 is not backward compatible with version 1. Make sure to carefully read the changelog.
Using Silex-Routing is very simple. All you need to do is register the provided
RoutingServiceProvider
and afterwards add all your custom routers
(RouterInterface
).
$app = new \Silex\Application();
$app->register(new \ChiliLabs\Silex\Provider\RoutingServiceProvider());
$router2 = new \Acme\Silex\MySpecialRouter();
$app['routers']->add($router);
...
There is a router in this repository named SilexRouter
, that handles the
default routing behavior of Silex. Registering this router ensures, that all
routes added through the main Silex application still work. (This router is not
registered by default.)
Since version 2.0 of project-a/silex-routing the url generation is included in the RoutingServiceProvider
and
no special UrlGeneratorServiceProvider
is needed anymore.
To run the test suite, you need composer.
$ php composer.phar install --dev
$ phpunit
Silex-Routing is licensed under the MIT license.