开发者

Injecting Criteria into an sfPropelRoute object

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:    开发者_C百科 /: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 sfPropelRoute offers the method_for_criteria option, but respects the method option of sfObjectRoute and uses it instead if it exists. If only method_for_criteria exists, then the sfPropelRoute class 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 method option, 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.


I'm not sure I understand your problem completely (I read this for the Propel tag, not the Symfony tag), but is the Advanced Routing chapter from the Advent Calendar of any help? The code is given for Doctrine, but I guess you can also adapt it for Propel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜