Commit 49ffb755 authored by Igor Wiedler's avatar Igor Wiedler

[docs] some documentation for the UrlGeneratorExtension

parent cc4b5758
...@@ -34,6 +34,7 @@ All of these are within the ``Silex\Extension`` namespace. ...@@ -34,6 +34,7 @@ All of these are within the ``Silex\Extension`` namespace.
* :doc:`MonologExtension <extensions/monolog>` * :doc:`MonologExtension <extensions/monolog>`
* :doc:`TwigExtension <extensions/twig>` * :doc:`TwigExtension <extensions/twig>`
* :doc:`UrlGeneratorExtension <extensions/url_generator>`
Creating an extension Creating an extension
--------------------- ---------------------
......
...@@ -6,3 +6,4 @@ Silex ...@@ -6,3 +6,4 @@ Silex
monolog monolog
twig twig
url_generator
UrlGenerator
============
The *UrlGeneratorExtension* provides a service for generating
URLs for named routes.
Parameters
----------
None.
Services
--------
* **url_generator**: An instance of
``Symfony\Component\Routing\Generator\UrlGenerator``, using the
``RouteCollection`` that is provided through the ``routes`` service.
It has a ``generate`` method, which takes the route name as an argument,
followed by an array of route parameters.
Registering
-----------
::
use Silex\Extension\UrlGeneratorExtension;
$app->register(new UrlGeneratorExtension());
Usage
-----
The UrlGenerator extension provides a ``url_generator`` service.
::
$app->get('/', function() {
return 'welcome to the homepage';
})
->bind('homepage');
$app->get('/hello/{name}', function($name) {
return "Hello $name!";
})
->bind('hello');
$app->get('/navigation', function() use ($app) {
return '<a href="'.$app['url_generator']->generate('homepage').'">Home</a>'.
' | '.
'<a href="'.$app['url_generator']->generate('hello', array('name' => 'Igor')).'">Hello Igor</a>';
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment