wowpatrick
wowpatrick

Reputation: 5180

Symfony 2 - Point multiple URLs to one controller?

How can I point multiple URLs to one controller? I've tried this:

pattern: /
defaults: { _controller: myTestController:Intro:index }
pattern: /intro
defaults: { _controller: myTestController:Intro:index }

But the first rule seems to be ignored and only the second one is being read.

Upvotes: 1

Views: 2159

Answers (1)

Ahmed Siouani
Ahmed Siouani

Reputation: 13891

Each route must be defined separately. And don't use the same identifier, otherwise you'll override the first route definition.

myFirstRoute:
    pattern: /
    defaults: { _controller: airpaprFramesWebsiteBundle:Intro:index }
myDuplicateRoute:
    pattern: /intro
    defaults: { _controller: airpaprFramesWebsiteBundle:Intro:index }

This may also help > symfony2 use multiple url pattern for a single Controller Action using regular expression

Next time, try to use app/console router:debugcommand line to check your routes definition and figure out what's going wrong.

Upvotes: 3

Related Questions