Reputation: 329
How can I find a record from a repository in the controller:
$em = $this->getDoctrine()->getRepository('ShopMyShopBundle:Product')->find($value);
Can I do something like this in template ?
{{ em.name }}
Upvotes: 0
Views: 4556
Reputation: 1460
It depends on what is in $value
. Method find()
will finb by id
. If you want to search by for example slug
, you have to call method findBySlug()
or equivalent findOneBySlug()
.
Upvotes: 1
Reputation: 6636
In a controller:
$em = $this->get('doctrine')->getEntityManager();
$product = $em->getRepository('ShopMyShopBundle:Product')->find($value);
You can not do this in template. Feel free to read documentation.
Upvotes: 0