How Symfony 2 manages route conflicts with the same name

1

I'm using annotations in the project.

In the file routing.yml I have the following configuration:

acme_store:
    resource: "@AcmeStoreBundle/Controller/"
    type:     annotation
    prefix:   /acme

teste_blog:
    resource: "@TesteBlogBundle/Controller/"
    type:     annotation
    prefix:   /

Note that in the% bundle% with% I am using the AcmeStore prefix.

In the controller class acme of the bundle DefaultController.php , I have the following configured route:

/**
 * @Route("/", name="index")
 */
public function indexAction()
{
    return $this->render('AcmeStoreBundle:Default:index.html.twig');
}

In the controller class AcmeStore of the bundle DefaultController.php , I have the following configured route:

/**
 * @Route("/", name="index")
 */
public function indexAction()
{
    return $this->render('TesteBlogBundle:Default:index.html.twig');
}

Notice that the TesteBlog property is equal in both controllers.

At the console, running the command name returns the following result:

------- ------- ------- ----- -----
Name    Method  Scheme  Host  Path                               
------- ------- ------- ----- -----
index   ANY     ANY     ANY   /    

Should not there be another line?

------- ------- ------- ----- -----
Name    Method  Scheme  Host  Path                               
------- ------- ------- ----- -----
index   ANY     ANY     ANY   / 
index   ANY     ANY     ANY   /acme

If even using a prefix we can not use the same php app/console debug:router for different routes, what are the best practices when we choose a name for the route?

I ask this because it is possible to install third-party bundles and this can lead to conflicts.

    
asked by anonymous 10.03.2016 / 15:28

2 answers

1

You should not have the same name to indicate different routes! (as there is no same cpf to identify different people) I say different because if they were the same it would not make sense to have two, there is something differs between them.

Regarding the good practice you can follow the example of the fosUserBundle that uses the bundle name always in its routes. EX: fos_user_change_password.

In your case it would be teste_index and acme_index.

How to Match a Route Based on the Host

    
14.03.2016 / 21:54
1

When I name the routes for my application, I usually use the following methodology:

{bundle}_{controller}_{action}

However, you have the option to leave the name empty. In this way, the framework automatically determines the route name. Then you can see the path names in the command app/console router:debug (in the case of Symfony 3.0).

    
18.03.2016 / 14:40