Symfony: sfDoctrineRoute pass optional parameter

I am using symfony 1.4 and I have the following route for my / -Route:

homepage: url: / class: sfDoctrineRoute options: { model: ContentPage, type: object} param: { module: page, action: show} 

and my show action is as follows:

 class pageActions extends sfActions { public function executeShow(sfWebRequest $request) { $this->content_page = $this->getRoute()->getObject(); $this->forward404Unless($this->content_page); $this->forward404Unless($this->content_page->getPublished()); } } 

It works, but it always selects the first record in the ContentPage-Table. Is there a way to pass a "Doctrine-Select-Parameter" inside routing.yml to use a specific identifier or so?

Regards, UHU.

+4
source share
1 answer

Take a look at the getObjectsForParameters() sfDoctrineRoute method. As you can see, you can use the method option in the route definition to determine which table method is used to get the results. You can add your condition to this method.

The second solution is to use the method_for_query parameter to specify which table model method will be used to modify the query and get the results.

+4
source

Source: https://habr.com/ru/post/1334270/


All Articles