Symfony2: routing priority

Anyway, to prioritize routes in Symfony2?

I use annotation, it looks like

Controllers

//TestController.php

/**
 * @Route("/test")
 */
class TestController extends Controller
{
    /**
     * @Route("/a", name="test_a")
     */
   .....

//DummyController.php
/**
 * @Route("/")
 */
class DummyController extends Controller
{
    /**
      * @Route("/{varA}/{varB}", name="dummy_one")
      */
   .....

Config

//routing.yml

acme_bundle:
    resource: "@Acme/Controller"
    type:     annotation

purpose

URL      , Actual              , Goal
/test/a  , DummyController     , TestController  //Wrong
/test/b  , DummyController     , DummyController //Good

How can I get TestController to be tested first?

thank

+3
source share
3 answers

So, Symfony will consume the controllers in alphabetical order and will add routes one by one.

there is no way to add priority at the moment without using another package for this currently version 2.5

https://github.com/symfony-cmf/Routing is a great bundle if you are looking for advanced routing.

+3
source

, , , routing.yml. , , - , .

acme_test:
    resource: "@Acme/Controller/TestController.php"
    type:     annotation

acme_dummy:
    resource: "@Acme/Controller/DummyController.php"
    type:     annotation

, .

. symfony. http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html#activation

+8

You do not need to reorder everything. Just rewrite the rules for DummyController in the desired ranking. You can do this by creating a route to the controller at the end of your route. Therefore, in your routing.yml, as the last lines, you add:

app_dummy:
    ressource: "@YourBundle/Controller/DummyController.php
    type:     annotation
0
source

All Articles