Has anyone face this strange issue with Symfony 3 (very last version)?
I have the following simple code:
$repository = $this->getDoctrine()
->getManager()
->getRepository('GeneralRegistrationBundle:Service');
$service = $repository->findOneBy(array('name' => 'Registration'),array('name' => 'ASC'));
$comment = $service->getComment();
$name = $service->getName();
return new Response('le service is '. $name . ', content is ' . $comment);
this code works.
I purge the cache and change findOneBy
with findBy
:
$service = $repository->findBy(array('name' => 'Registration'),array('name' => 'ASC'),1 ,0);
then I have the following error:
Error: Call to a member function getComment() on array
Is anybody have ideas or clues?
Thanks in advance.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With