0

私は Symfony 3 を使用しており、symfony がルートを選択する方法を理解したいと考えています。

routing.yml に 2 つ、注釈に 1 つの 3 つのルートがあります。これは私のコードです:

アプリ/構成/ルーティング.yml

app:
    resource: "@AppBundle/Controller/"
    type:     annotation

hello:
    path: "hello/{firstName}"
    defaults: {_controller: AppBundle:Default:rotta,firstName: "route1"}

hello_name:
    path: "hello/{firstName}"
    defaults:  {_controller: AppBundle:Default:rotta, firstName: "route2"}

src/AppBundle/Controller/DefaultController.php

/**
 * @Route("hello/{firstName}", name="hello", defaults={"firstName" = "Annotation"})
 */
public function rottaAction($firstName,Request $request)
{
    var_dump($request->get('firstName'));
    exit;
}

私の結果は

string 'route1' (length=6)

このrouting.ymlで

hello:
    path: "hello/{firstName}"
    defaults: {_controller: AppBundle:Default:rotta,firstName: "route1"}

hello_name:
    path: "hello/{firstName}"
    defaults:  {_controller: AppBundle:Default:rotta, firstName: "route2"}

app:
    resource: "@AppBundle/Controller/"
    type:     annotation

私の結果は

string 'route2' (length=6)

そしてこの組み合わせで:

hello:
    path: "hello/{firstName}"
    defaults: {_controller: AppBundle:Default:rotta,firstName: "route1"}

hello_name:
    path: "hello/{firstName}"
    defaults:  {_controller: AppBundle:Default:rotta, firstName: "route2"}

#app:
#    resource: "@AppBundle/Controller/"
#    type:     annotation

私の結果は次のとおりです。

string 'route1' (length=6)
4

0 に答える 0