Passing Params to Symfony Routes
I have a defined route that displays a dynamic page:
page_show:
url: /:domain_slug/:slug
class: sfPropelRoute
options:
model: Page
type: object
method: doSelectByDomain
param: { module: page, action: show }
requirements:
sf_method: [get]
This works great, but now I 开发者_开发百科want my homepage URI to route to a specific page. To do that, I assume that I have to pass the :domain_slug
and :slug
values of the page I want to display as the homepage. That's fine, but I can't seem to track down any documentation or example that shows me how to go about doing that.
Is it possible to specify specific variable values in a route? In this case, I want to pass :domain_slug => portal, :slug => dashboard
(that syntax doesn't work, btw). Essentially, I want to create a homepage route that looks something like this:
homepage:
url: /
class: sfPropelRoute
param: { module: page, action: show, array( :domain_slug => portal, :slug => dashboard ) }
options:
model: Page
type: object
method: doSelectByDomain
But different enough that it, you know, works. :-) I suppose I could create a simple route to a different method, modify the request parameters manually and forward to the executeShow()
method, but that's a hack I'd rather avoid if a more elegant solution is available.
Thanks.
You can define values in the param
key of the route... for example:
homepage:
url: /
class: sfPropelRoute
param: { module: page, action: show, domain_slug: portal, slug: dashboard}
options:
model: Page
type: object
method: doSelectByDomain
At least thats how it works with a non propel/doctrine route. I assume it should be the same with any type of route in the framework.
I never found a way to do this that worked (or maybe I just couldn't manage to do it correctly). My solution was to create the route and pass it through a custom method that does the work to specify the appropriate page details:
homepage:
url: /
class: sfPropelRoute
options:
model: Page
type: object
method: doSelectHomepage
param: { module: page, action: show ) }
requirements:
sf_method: [get]
The doSelectHomepage()
method does all of the work I was hoping I'd be able to do by hardcoding values in the route itself.
Actually it did work, it was just the order in which the routes were defined. The first answer is correct. It may have worked for you if you added "homepage" rule BEFORE the "page_show" rule. So maybe Symfony isn't as stupid as I thought...No, no, it is. It's just not that bad.
精彩评论