tags:

views:

73

answers:

1

I'm starting a new project - my first with Symfony - and I'm trying to figure out how to construct a route that incorporates information about an associated object. The documentation that I can find is light, to say the least, and I'm struggling. I'm using v1.4.1 w/ Propel (backwards compatibility with some existing stuff) and have:

A navigation menu (Menu) that has_many pages (Page) through a navigation item (NavItem)

I realize that syntax doesn't really apply to Propel, but you get the idea, I hope. I'd like to access a page through a URI that includes it's menu and page slugs. For example, to display the page named Find an Audience on the Audiences menu, I'd like to use /audiences/find. The route, then, for @page_show would look something like /:menu_slug/:slug.

The relevant snippet of the schema lays out like this:

Menu:
  id: ...
  name: ...
  slug: ...

Page:
  id: ...
  name: ...
  slug: ...

NavItem:
  menu_id: ...
  page_id: ...
  display_order: ...

I may also be off on some of the routing specifics, but what I'm not sure how to do is configure my route in its entirety (including how to reference it in my layouts/templates using the link_to() and url_for() helpers.

Solutions or anything just to get me started in the right direction would be much appreciated.

Thanks.

A: 

You should take a look at this:

http://www.symfony-project.org/jobeet/1%5F4/Propel/en/05

It covers your answer fairly well. Starts off with a general intro to the routing and how it works, which is well worth reading.

Then goes on to cover object routes and object route collections, how to use url_for/link_to and how to customise urls with slugs etc.

benlumley
I've done the tutorial (Jobeet) and the routing part is pretty comprehensive, but I don't see where it speaks to this particular case. The `:menu_slug` value isn't in my `page` table as the example shows with the `Job` route(s). I may not be processing the information fully, but I have read it (and coded the example app). Promise.In this case, I don't need the collection, just one route (for a `Page`) who's URI references a `Menu` property and a `Page` property. I'm just not seeing how to get there yet.
Rob Wilkerson
Okay, so you were right. The Jobeet tutorial ultimately did answer the question I was asking. A second read got me to virtual accessors which allowed the URI helpers to understand what I was trying to do. thanks.
Rob Wilkerson