Here is our controller:
function getLocationsAction(Request $request) {
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$query = $dm->createQueryBuilder('MainClassifiedBundle:Location')->select('name', 'state', 'country', 'coordinates');
$locations = $query->getQuery()->execute();
$data = array(
'success' => true,
'locations' => $locations,
'displaymessage' => $locations->count() . " Locations Found"
);
$view = View::create()->setStatusCode(200)->setData($data);
return $this->get('fos_rest.view_handler')->handle($view);
}
Here is the config.yml for fosrestbundle:
fos_rest:
view:
formats:
json: true
templating_formats:
html: true
force_redirects:
html: true
failed_validation: HTTP_BAD_REQUEST
default_engine: twig
Here is the route:
MainClassifiedBundle_get_locations:
pattern: /locations/
defaults: { _controller: MainClassifiedBundle:ClassifiedCrudWebService:getLocations, _format:json}
requirements:
_method: GET
Why are we getting text/html ? Ho wcan we force the response to be application/json?
Please help as this is causing huge pains at the moment