php - URL alias or replace with symfony2
936
I have the application which generates urls like this
ex)
http://myserver.com/shows/12
http://myserver.com/shows/14
My routing.yml is
acme_top_writeReviewSchool:
pattern: /show/{userId}
defaults: { _controller: AcmeTopBundle:Default:showUser}
12 or 14 is id used in database.
id| name | position
12| james| pitcher
14| nick | short
15| ian | catcher
Now,what I would like to make alias for this urls
http://myserver.com/james
http://myserver.com/nick
or
http://myserver.com/u=james
http://myserver.com/u=nick
or
http://myserver.com/show/james
http://myserver.com/show/nick
I have googled with keywords like 'alias' 'url exchange' or something, howevere can't find good example or bundle.
Could you help me?
Answer
Solution:
You can actually have multiple routes pointing to the same bundle:controller:action.
For example if you want to use http://myserver.com/james
The only thing you have to be aware of is that in the controller action you need to either pass the Request object to get either the param "name" or "userId", Alternatively you could name the param the same and manage it by hand (so to speak).
Could you post the controller action here also?