I've set up FOSRestBundle with my small Symfony2 website. I've created some small GET methods and when I visit the api url, I get my JSON data. Perfect. But I'm trying to build an iphone app and I use RestKit for mapping/parsing json/... The problem I'm experiencing is that it has to be Key-value coding (KVC) JSON data.
I use this basic code in my ApiController to retrieve all data from my Sports database table:
public function getSportsAction() {
$sports = $this->getDoctrine()
->getRepository('MatchTrackerAppBundle:Sports')
->findAll();
$view = View::create()
->setStatusCode(200)
->setData($sports);
return $this->get('fos_rest.view_handler')->handle($view);
}
At the moment I get this output:
[
{
"id": 1,
"name": "Voetbal"
},
{
"id": 2,
"name": "Tennis"
}
]
It doesn't have a key! How can I add a key in front of it. What I want is:
{
"sports": [
{
"id": 1,
"name": "Voetbal"
},
{
"id": 2,
"name": "Tennis"
}
]
}
Is this possible with FOSRestBundle?