I'm building a RESTful API which is retuing a JSON response. When setting the view vars in the controller, is there a way to explicitly set elements of an array variable which already exists?
For example, let's say the AppController sets a view var which is an array:
$this->set('myArray', array('foo' => 'bar'));
But then in the child controller MyController I want to add to that array. Something like:
$this->set('myArray.add', 'New Element');
So that the JSON response for the view will be:
{
"myArray": {
"foo": "bar",
"add": "New Element"
}
}
I'm guessing it can be done in a roundabout way by storing the array as a normal PHP property of the AppController class, and then adding to the array in the child controller before finally doing $this->set() once at the end of the controller action.
But I'm curious if there is a way to do this through the Controller::set() method alone.
