Reputation: 309
I couldn't find it anywhere. So I ask: On silex, why do we use bind() for? For example, on this routing of static pages:
$pages = array(
'/' => 'index',
'/blog' => 'blog',
'/about' => 'about',
);
foreach($pages as $route => $view) {
$api->get($route, function(Silex\Application $app) use($view) {
return $app['twig']->render($view.'.html');
})->bind($view);
}
Upvotes: 3
Views: 4632
Reputation: 1860
From the silex documentation:
Some providers (such as
UrlGeneratorProvider
) can make use of named routes. By default Silex will generate a route name for you, that cannot really be used. You can give a route a name by calling bind on the Controller object that is returned by the routing methods:
$app->get('/', function () {
...
})->bind('homepage');
$app->get('/blog/{id}', function ($id) {
...
})->bind('blog_post');
It only makes sense to name routes if you use providers that make use of the
RouteCollection
.
Upvotes: 0
Reputation: 99687
For an event-heavy framework, it's a bit of a poor choice, but this basically names the route.
Things like providers can get access to the routes if they are given a name.
Relevant documentation:
Upvotes: 9