That’s the thing, though. I’m not using Cake (or even PHP) at all to encode anything. The DB already does that for me.
Here is a simple example of what I mean. This is my query.
select array_to_json(array_agg(f))
from
(SELECT id
, site_id
, ST_Npoints(polygon) as points
, ST_Area(polygon::geography) * 0.000001 as area
from convex_hulls
where hull_type = 2
) as f
");
That returns a single row, an array of records in JSON format.
It looks like this
"{"data":[{"id":111917,"site_id":3076021581,"points":4,"area":6163.60421897346},{"id":111759,"site_id":3076021581,"points":4,"area":6163.60421897346}]}"
That is already JSON encoded. I don’t need Cake or PHP to do anything with it other than return it as the body of the response…
Connection:Keep-Alive
Content-Length:141
Content-Type:application/json; charset=UTF-8
Date:Sat, 27 Aug 2016 16:35:06 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.6 (Red Hat Enterprise Linux) PHP/5.6.23
X-DEBUGKIT-ID:96902bf2-6336-42e3-ab3c-ad9f42d5b72d
X-Powered-By:PHP/5.6.23
{"data":[{"id":111917,"site_id":3076021581,"points":4,"area":6163.60421897346},{"id":111759,"site_id":3076021581,"points":4,"area":6163.60421897346}]}
But any time I set the content-type appropriately to JSON, Cake wants to json_encode it for me. So I’m setting the content type to text/plain, which gives me the server side behavior that I want (unmolested data) but forces me to treat it differently on the client side (having to parse it with JSON.parse()).
Does that clarify my problem a bit?
Thanks for the help!