diff --git a/book/routing.rst b/book/routing.rst index b5cc3da9715..604110c0dee 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -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 + + + + + + + AppBundle:Main:new + + + + .. 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 ~~~~~~~~~~~~~~~~~~~~~~~~~