rest - Remove Square Brackets - Json Data - CakePHp RESTful -
i using cakephp create restful api connected via emberjs front end.
the following code within cakephp generating json need putting in square brackets emberjs doesn't like. how go getting data without square brackets?
cakephp view
public function view($id = null) { if($id == null) { $id = $this->request->params['id']; } $this->layout = 'ajax'; $options = array('conditions' => array('content.' . $this->content->primarykey => $id)); $content = $this->content->find('first', $options); $content = set::extract('/content/.', $content); $this->set('content', $content); $this->set('_serialize', $content); ; }
view.ctp
echo json_encode(compact('content'));
it returning this:
{ "content": [{ "id":"1", "name":"home", "extended":"this homepage.", "created":"2013-08-05 23:40:55", "modified":"2013-08-05 23:40:55" }] }
i need this:
{ "content": { "id":"1", "name":"home", "extended":"this homepage.", "created":"2013-08-05 23:40:55", "modified":"2013-08-05 23:40:55" } }
thankyou
square brackets arrays in javascript/json. apparently need object (i've never used emberjs). so:
json_encode(compact('content'),json_force_object);
Comments
Post a Comment