Reputation: 1244
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'
}
Upvotes: 2
Views: 6206
Reputation: 654
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
}
Upvotes: 8
Reputation: 6439
Create a new method in your repository for proxy the call
findSlugXXXX($slug) {
$this->findWithSomeFeaturesBySlug(array('slug' => $slug));
}
Upvotes: 0