2013-04-01 2 views
0

나는 URI의 포맷 단일 경로 패턴을Symfony2 라우팅 경로/패턴

1 hello/first.format 
2 hello/first 
3 hello/first/last.format 
4 hello/first/last 
이 필요

및 마지막 을 사용하여 다음과 같은 구성하고자는 선택적 매개 변수와 형식을 선택.

hello-route: 
    pattern: /hello/{fist_name}/{last_name}.{_format} 
    defaults: { _controller: AcmeHelloBundle:Default:index, last_name:Default, _format:html} 
requirements: 
    _format: html|rss|json 
    first_name: \w+ 
    last_name: \w+ 

하지만, 3을 2 일치로 정확하지 않은, 4 아니지만 1. 1은 실패하지 않습니다,하지만 먼저 "로 {FIRST_NAME} 일치합니다 :

내가 시도 것입니다 .format "필요성에도 불구하고.

기본 라우팅을 사용하여 어떻게 할 수 있습니까?

답변

1

그런 다음 컨트롤러 옵션은 $ LAST_NAME의 주장을이

hello-route-first: 
    pattern: /hello/{fist_name}.{_format} 
    defaults: { _controller: AcmeHelloBundle:Default:index, _format:html} 
requirements: 
    _format: html|rss|json 
    first_name: \w+ 

hello-route-last: 
    pattern: /hello/{fist_name}/{last_name}.{_format} 
    defaults: { _controller: AcmeHelloBundle:Default:index, _format:html} 
requirements: 
    _format: html|rss|json 
    first_name: \w+ 
    last_name: \w+ 

을 달성하기 위해 두 개의 경로를 정의

function indexAction($first_name, $last_name = "") 
    { 
관련 문제