a Symfony2 newbie question.
What do I miss in the following code (it returns a "Call to a member function getArrayResult() on a non-object)"
/**
* Lists all Post entities.
*
* @Route("/jsonout", name="Mario_Post_jsonout")
* @Method("GET")
* @Template()
*/
public function jsonoutAction()
{
$response = new Response();
$em = $this->getDoctrine()->getEntityManager();
$query = $this->getDoctrine()
->getRepository('MarioBlogBundle:Post')
->createQueryBuilder('e')
->select('e')
->getQuery();
$results = $query->execute();
$myArray = $results->getResult(Query::HYDRATE_ARRAY); // neither ->getArrayResult();
$response->setContent(json_encode($myArray));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
Do I need to use a 'use Doctrine\ORM.....;' line? which one exactly? Thanks