I have a Page object whose uniqueness comes from its PageDomain. The schema is configured such that the page table contains a page_domain_id field to create the relationship. To show a page, I have an executeShow action and a custom handler. My route looks like this:
page_show:
url: /:domain_slug/:slug
class: sfPropelRoute
options:
model: Page
type: object
method_for_criteria: doSelectByDomain
param: { module: page, action: show }
requirements:
sf_method: [get]
By way of an example, I might have /audience/create and also /behavior/create. I need to be able to determine which page is being requested.
The intent of the custom handler (doSelectByDomain) is to factor in the domain_slug and only retrieve/show a page if its domain is also correct. What I’m finding, though, is that even though a domain_slug parameter is available in the action’s $request parameter, I have no way of getting it to my custom handler so that it can be factored into what’s retrieved.
I realize that I can access the sfContext object directly from my model, but that’s inelegant at best and breaks MVC. I’m not afraid to use it if there’s really no better way, but it seems like there must be. Symfony offers a setListCriteria method for list routes, but I can’t find anything similar for object routes.
Help? Thanks.
So a little venture through the source code got me where I needed to be. It seems that
sfPropelRouteoffers themethod_for_criteriaoption, but respects themethodoption ofsfObjectRouteand uses it instead if it exists. If onlymethod_for_criteriaexists, then thesfPropelRouteclass creates a criteria object from the request parameters.Except that it doesn’t include any parameters that aren’t properties of the object. I understand that there’s an argument to be made for that behavior, but in my opinion it’s a mistake.
Anyway, the short version is that if you use the
methodoption, all parameters are passed (without edit) as an array to the specified handler. If you need request parameters other than those that are properties of the object, this appears to be the way to go.