I have a situation in which I want to query the database with findOneBy($id) method from doctrine in symfony2.
$namePosting = $this->getDoctrine()->getRepository('MyBundle:Users')->findOneById($userPosting);
The result it's an object with protected properties. I want to return it directly an array. How can this be done ?
findOneBy(array())
will always return null or object.But you can use instead
findById($userPosting)
orfindBy(array('id' => $userPosting))
and it will return an array, e.g.:Edited
Or you can add a method in
UserRepository
class: