Using Zend Framework 2 and an AbstractRestfulController where the getList action is implemented like this:
public function getList() {
return new ViewModel(array(
'entities' = array(1 => array(/*..*/), 2 => array(/*..*/))
));
}
I've added the JsonStrategy to the view manager so when my UA sends Accept: text/html
ZF2 uses the correct view to format the data. When my UA sends Accept: application/json
ZF2 (correctly) responds with application/json
and JSON encodes the data.
But now the all the entities are wrapped inside a 'content' node (the ViewModel::$captureTo
property).
If the action controller returns a JsonModel I can avoid this. But then the JsonStrategy always responds with application/json, without checking Accept.
Is there any way to avoid it while still using the ViewModel, and not the JsonModel?