Skip to content

Commit

Permalink
[Book][Routing] Add example about how to match multiple methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xelaris committed Apr 21, 2015
1 parent 318bb8a commit 6f854f9
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,67 @@ form via the same URL, while using distinct controllers for the two actions.

If no ``methods`` are specified, the route will match on *all* methods.

A route can also match multiple methods. This is useful if you want to
handle form presentation and processing in a single action for example.

.. configuration-block::

.. code-block:: php-annotations
// src/AppBundle/Controller/MainController.php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
// ...
class MainController extends Controller
{
/**
* @Route("/new")
* @Method({"GET", "POST"})
*/
public function newAction()
{
// ... display or process form
}
}
.. code-block:: yaml
# app/config/routing.yml
new:
path: /new
defaults: { _controller: AppBundle:Main:new }
methods: [GET, POST]
.. code-block:: 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="new" path="/new" methods="GET|POST">
<default key="_controller">AppBundle:Main:new</default>
</route>
</routes>
.. code-block:: php
// app/config/routing.php
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
$collection = new RouteCollection();
$collection->add('new', new Route('/new', array(
'_controller' => 'AppBundle:Main:new',
), array(), array(), '', array(), array('GET', 'POST')));
return $collection;
Adding a Host Requirement
~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 6f854f9

Please sign in to comment.