I need to return $items array from 'http://localhost:8000/cart/viewall'
controller action. But all i get is this error.
The Response content must be a string or object implementing __toString(), "array" given.
This is my code,
/**
* @Route("/cart/viewall")
* @Template()
*/
public function viewallAction() {
$items = array(1 => 'item 1', 2 => 'item 2');
return new Response($items);
}
It would be great help if someone can supply a solution.
new JsonResponse($items);and you have to use the gooduse ....\JsonResponse;new Responselike a call toecho. This is a response to the browser and it has to be a string.