In an entity, I've define a slug with the DoctrineExtension, I use it in my href. But... I've a problem with the Router and/or ParamConverter.
In my controller:
/**
* @Route("/{slug}", name="strain_view")
* @ParamConverter("strain", class="AppBundle:Strain", options={
* "repository_method" = "findOneWithAll",
* })
* @Security("is_granted('STRAIN_VIEW', strain)")
*/
public function viewAction(Strain $strain)
{
return $this->render('strain/view.html.twig', [
'strain' => $strain,
]);
}
And I've this error:
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
In the debug bar, I see, the problem is the array in array:
Parameters: [ 0 => [ slug => t1p-0004-e-coli-pgem-t-promupf3-leu2-termupf3 ] ]
When I replace in @Route: {slug} by {id} and I manually type the url, I've
Parameters: [0 => t1p-0004-e-coli-pgem-t-promupf3-leu2-termupf3]
And... it's work, but in my Repository I've:
public function findOneWithAll($slug)
{
$query = $this->createQueryBuilder('strain')
->where('strain.slug = :slug')
->setParameter('slug', $slug)
->getQuery();
I don't understand why.