phproutespropertiessymfony1criteria

Passing a propel criteria to the symfony routing method that retrieves the object


I have the following propel collection route:

api_offer:
  class: sfPropelRouteCollection
  options:
    prefix_path: /api/offer
    model: Offer
    plural: offers
    singluar: offer
    actions: [ list ]
    module: apiOffer
  requirements:
    sf_format: (?:html|json)

Does anyone know of a way to pass a Criteria to the $this->getRoute()->getObjects() method in the action? Basically, I need to retrieve different objects from the database depending on existing parameters in the route.


Solution

  • sfPropelRouteCollection has an inherited option from sfObjectRouteCollection called model_methods. This is how it gets used:

    protected function getRouteForList()
    {
        return new $this->routeClass(
            sprintf('%s.:sf_format', $this->options['prefix_path']),
            array_merge(
                [
                    'module' => $this->options['module'],
                    'action' => $this->getActionMethod('list'),
                    'sf_format' => 'html'
                ],
                $this->options['default_params']
            ),
            array_merge(
                $this->options['requirements'],
                ['sf_method' => 'get']
            ),
            [
                'model' => $this->options['model'],
                'type' => 'list',
                'method' => $this->options['model_methods']['list']
            ]
        );
    }