Symfony findOneBy / findBy Symfony findOneBy / findBy symfony symfony

Symfony findOneBy / findBy


findBy() returns an array of objects with the given conditions.

It returns an empty array if none is found. If there is only one row satisfying your condition then you can add a [0] at the last of your $service like this:

$service = $repository->findBy(array('name' => 'Registration'),array('name' => 'ASC'),1 ,0)[0];

if not, you should loop through the found array with foreach or some thing similar.