I have an old cakephp 2 project that i used the .json extension for some actions to return json. In cakephp 2.x it returned an array of entities (shows) from the database. When I try to do the same in cakephp 4.x it returns an array of arrays i think. Any ideas how to get the same output in cakephp 4.x?
screenshot below of output
$shows = $this->Shows->find( 'all' );
$this->set( 'shows', $shows );
$this->set( compact( 'shows' ) );
$this->set( '_serialize', array( 'shows' ) );
2.x returned arrays from queries, and they always had that extra level in them so you would know what kind of data it was. With the ORM (3.x and newer), it returns entities, so that extra level is not necessary. It’s possible to add it, but it’s not going to be trivial, and the customization will add to your ongoing maintenance burden. Any chance you can make the change on the consumer side instead of the producer? It might well be a smaller change there, and likely to remove code complexity instead of increase it.
Thanks. I guess I was thinking that would be the easier route. The front end is an android app that I haven’t updated in many years but is still in use by users. Trying to update the back end server to a new version of the OS. Also tried to update the os and keep the older version of php and the app as is but haven’t been able to get that to work.