Commit 0a19eee5 authored by Fabien Potencier's avatar Fabien Potencier

removed the now obsolete UrlGenerator service provider

parent 48a3fdc4
......@@ -58,7 +58,6 @@ the ``Silex\Provider`` namespace:
* :doc:`SwiftmailerServiceProvider <providers/swiftmailer>`
* :doc:`TwigServiceProvider <providers/twig>`
* :doc:`TranslationServiceProvider <providers/translation>`
* :doc:`UrlGeneratorServiceProvider <providers/url_generator>`
* :doc:`ValidatorServiceProvider <providers/validator>`
* :doc:`HttpCacheServiceProvider <providers/http_cache>`
* :doc:`FormServiceProvider <providers/form>`
......
......@@ -10,7 +10,6 @@ Silex
swiftmailer
translation
twig
url_generator
validator
form
http_cache
......
......@@ -61,11 +61,16 @@ some Symfony components and Twig. Add it as a dependency:
When present, the ``TwigServiceProvider`` will provide you with the following
additional capabilities:
* **UrlGeneratorServiceProvider**: If you are using the
``UrlGeneratorServiceProvider``, you will have access to the ``path()`` and
``url()`` functions. You can find more information in the `Symfony Routing
documentation
<http://symfony.com/doc/current/book/routing.html#generating-urls-from-a-template>`_.
* Access to the ``path()`` and ``url()`` functions. You can find more
information in the `Symfony Routing documentation
<http://symfony.com/doc/current/book/routing.html#generating-urls-from-a-template>`_:
.. code-block:: jinja
{{ path('homepage') }}
{{ url('homepage') }} {# generates the absolute url http://example.org/ #}
{{ path('hello', {name: 'Fabien'}) }}
{{ url('hello', {name: 'Fabien'}) }} {# generates the absolute url http://example.org/hello/Fabien #}
* **TranslationServiceProvider**: If you are using the
``TranslationServiceProvider``, you will get the ``trans()`` and
......
UrlGeneratorServiceProvider
===========================
The *UrlGeneratorServiceProvider* provides a service for generating URLs for
named routes.
Parameters
----------
None.
Services
--------
* **url_generator**: An instance of `UrlGenerator
<http://api.symfony.com/master/Symfony/Component/Routing/Generator/UrlGenerator.html>`_,
using the `RouteCollection
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
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
-----------
.. code-block:: php
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
Usage
-----
The UrlGenerator provider 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>';
});
When using Twig, the service can be used like this:
.. code-block:: jinja
{{ app.url_generator.generate('homepage') }}
Moreover, if you have ``twig-bridge`` as a Composer dep, you will have access
to the ``path()`` and ``url()`` functions:
.. code-block:: jinja
{{ path('homepage') }}
{{ url('homepage') }} {# generates the absolute url http://example.org/ #}
{{ path('hello', {name: 'Fabien'}) }}
{{ url('hello', {name: 'Fabien'}) }} {# generates the absolute url http://example.org/hello/Fabien #}
.. warning::
If you try to use the ``url_generator`` service outside the handling of a
request, you must explicitly flush routes first::
$app->flush();
$url = $app['url_generator']->generate('homepage');
Traits
------
``Silex\Application\UrlGeneratorTrait`` adds the following shortcuts:
* **path**: Generates a path.
* **url**: Generates an absolute URL.
.. code-block:: php
$app->path('homepage');
$app->url('homepage');
......@@ -184,6 +184,14 @@ Silex defines a range of services.
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
that is used internally. You can add, modify, read routes.
* **url_generator**: An instance of `UrlGenerator
<http://api.symfony.com/master/Symfony/Component/Routing/Generator/UrlGenerator.html>`_,
using the `RouteCollection
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
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.
* **controllers**: The ``Silex\ControllerCollection`` that is used internally.
Check the *Internals* chapter for more information.
......@@ -215,6 +223,20 @@ Silex defines a range of services.
the ``MonologServiceProvider`` or define your own ``logger`` service that
conforms to the PSR logger interface.
Core traits
-----------
* ``Silex\Application\UrlGeneratorTrait`` adds the following shortcuts:
* **path**: Generates a path.
* **url**: Generates an absolute URL.
.. code-block:: php
$app->path('homepage');
$app->url('homepage');
Core parameters
---------------
......
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