Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
0a19eee5
Commit
0a19eee5
authored
Aug 22, 2015
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed the now obsolete UrlGenerator service provider
parent
48a3fdc4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
94 deletions
+32
-94
doc/providers.rst
doc/providers.rst
+0
-1
doc/providers/index.rst
doc/providers/index.rst
+0
-1
doc/providers/twig.rst
doc/providers/twig.rst
+10
-5
doc/providers/url_generator.rst
doc/providers/url_generator.rst
+0
-87
doc/services.rst
doc/services.rst
+22
-0
No files found.
doc/providers.rst
View file @
0a19eee5
...
...
@@ -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>`
...
...
doc/providers/index.rst
View file @
0a19eee5
...
...
@@ -10,7 +10,6 @@ Silex
swiftmailer
translation
twig
url_generator
validator
form
http_cache
...
...
doc/providers/twig.rst
View file @
0a19eee5
...
...
@@ -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
...
...
doc/providers/url_generator.rst
deleted
100644 → 0
View file @
48a3fdc4
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');
doc/services.rst
View file @
0a19eee5
...
...
@@ -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
---------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment