tags:

views:

369

answers:

3

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.

+2  A: 

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.

prodigitalson
Yeah, I tried that too. When the workflow reaches my custom handler method (`doSelectByDomain`), no parameters are there. The array is completely empty.
Rob Wilkerson
A: 

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.

Rob Wilkerson