Skip to content

[Routing] Added a note about defining route requirements in the container #1827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,16 @@ the regular expression ``(en|fr)``.
| /es | *won't match this route* |
+-----+--------------------------+

.. sidebar:: Requirements defined in the container

If for some reason you need to define some configurable requirements,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not good in English grammar, but I think this should be:

If, for some reason, you need to define some configurable requirements,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me neither, I'm Cuban and I speak Spanish. Probably you are right. Thanks.

you can use a parameter from the service container. For instance, if you
have a _locale parameter in the routes and you like it to be configurable,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be

have a ``_locale`` parameter ...

you can do this: requirements: _locale: %locale%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to create a code block here or, even better, a configuration block with all formats:

you can do this:

.. configuration-block::

    .. code-block:: yaml

        requirements:
           _locale: %locale%

    .. code-block:: xml

        <!-- ... -->

    .. code-block:: php

        // ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add just a note, but you are right. Maybe it should be better if instead a note I add a section, then I will be able to add the configuration block. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, this isn't a note nor a section. It is a sidebare article, maybe a .. note:: is better.

Secondly, you can use configuration blocks/code blocks/what you want inside notes/sidebar articles, the Rst isn't limited on the syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip @wouterj. I'll do what you say.


Then just define in the container a locale parameter. This is quite useful
if you don't want to search all your code only to change a simple requirement.

.. index::
single: Routing; Method requirement

Expand Down