Skip to content

Clarify that route defaults don't need a placeholder #4017

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

Merged
merged 1 commit into from
Sep 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,10 @@ see :ref:`route-parameters-controller-arguments`.
You can also use a special ``$_route`` variable, which is set to the
name of the route that was matched.

You can even add extra information to your route definition and access it
within your controller. For more information on this topic,
see :doc:`/cookbook/routing/extra_information`.

.. index::
single: Routing; Importing routing resources

Expand Down
1 change: 1 addition & 0 deletions cookbook/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
* :doc:`/cookbook/routing/service_container_parameters`
* :doc:`/cookbook/routing/custom_route_loader`
* :doc:`/cookbook/routing/redirect_trailing_slash`
* :doc:`/cookbook/routing/extra_information`

* :doc:`/cookbook/security/index`

Expand Down
63 changes: 63 additions & 0 deletions cookbook/routing/extra_information.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.. index::
single: Routing; Extra Information

How to Pass Extra Information from a Route to a Controller
Copy link
Member

Choose a reason for hiding this comment

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

I think "extra" is a closed-class word and show be lowercased.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@weaverryan can you confirm this?

Copy link
Member

Choose a reason for hiding this comment

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

extra is an adjective, and adjectives are mostly (or always) considered open class words. So I think this should be upper-cased.

Copy link
Member

Choose a reason for hiding this comment

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

I see, I think I then did some lowercasing wrong in the past. Maybe I should do a re-check. :)

==========================================================

Parameters inside the ``defaults`` collection don't necessarily have to
match a placeholder in the route ``path``. In fact, you can use the
``defaults`` array to specify extra parameters that will then be accessible as
arguments to your controller:

.. configuration-block::

.. code-block:: yaml

Copy link
Member

Choose a reason for hiding this comment

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

I think you should add the filename as a comment inside the code block::

# app/config/routing.yml

# app/config/routing.yml
blog:
path: /blog/{page}
defaults:
_controller: AcmeBlogBundle:Blog:index
page: 1
title: "Hello world!"

.. code-block:: xml

Copy link
Member

Choose a reason for hiding this comment

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

same here:

<!-- app/config/routing.xml -->

<!-- app/config/routing.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="blog" path="/blog/{page}">
<default key="_controller">AcmeBlogBundle:Blog:index</default>
<default key="page">1</default>
<default key="title">Hello world!</default>
</route>
</routes>

.. code-block:: php

Copy link
Member

Choose a reason for hiding this comment

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

and here:

// app/config/routing.php

// app/config/routing.php
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;

$collection = new RouteCollection();
$collection->add('blog', new Route('/blog/{page}', array(
'_controller' => 'AcmeBlogBundle:Blog:index',
'page' => 1,
'title' => 'Hello world!',
)));

return $collection;

Now, you can access this extra parameter in your controller::

public function indexAction($page, $title)
{
// ...
}

As you can see, the ``$title`` variable was never defined inside the route path,
but you can still access its value from inside your controller.
Copy link
Member

Choose a reason for hiding this comment

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

[...] route path, but you [...]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xabbuh told me to remove this comma. Should I add it back?

Copy link
Member

Choose a reason for hiding this comment

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

@iamdto With the current wording I would add the comma as @wouterj suggested. There has been and "and" and not a "but" before, hasn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's right. I'll add it back.

Copy link
Member

Choose a reason for hiding this comment

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

👍 Sorry for the confusion.

1 change: 1 addition & 0 deletions cookbook/routing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Routing
service_container_parameters
custom_route_loader
redirect_trailing_slash
extra_information