Passing parameters to Symfony @ParamConverter

php, symfony

Solution

I had the same issue, fixed by adding the id option in the ParamConverter

/**
* @Route("/some-route/{slug}")
* @ParamConverter("object", class="AcmeBundle:Object", options={"id" = "slug", "repository_method" = "findWithSomeFeaturesBySlug"})
*/
public function acmeDemoAction(Object $object)
{
    // Controller code here
}

Problem

I'm using symfony @ParamConverter in my controller to get an entity by its slug, but instead of use the "findBySlug()" method I'm using a more specific one "findWithSomeFeaturesBySlug($slug)", and I have a problem because in the findWithSomeFeaturesBySlug($slug) method I receive the $slug parameter as an associative array with an 'slug' key instead of the slug's value. My controller's code looks like the following: ``` /** * @Route("/some-route/{slug}") * @ParamConverter("object", class="AcmeBundle:Object", options={"repository_method" = "findWithSomeFeaturesBySlug"}) */ public function acmeDemoAction(Object $object) { // Controller code here } ``` I hope that someone can help me. Thanks. UPDATE: I'm sorry, I think that I didn't explain my problem correctly. The problem is that I get an associative array in the "findWithSomeFeaturesBySlug($slug)" function and I need to get the $slug value directly. ``` // ObjectRepository public function findWithSomeFeatures($slug) { // here I get an associative array in the slug parameter: // $slug = array('slug' => 'some_value') // And I need $slug = 'some_value' } ```

Original source