Archive

Posts Tagged ‘json’

CakePHP common errors part 3

July 9th, 2010

This is a very strange error I have met in my last project, which is JSON data being cut off on my server when it is working fine on my localhost.

The case is I have an array($arrayData) with 300 length, and I am using $javascript->object($arrayData) to encode it to JSON in the view(json-view.ctp). It gives correct JSON data on my localhost, however when I moved the application to live server, it keeps on giving an incomplete JSON, which causes an incorrect JSON format. I tried to google for the solutions, some guys suggested to look into the php config file, to set max_execution_time and so on, but it did not solve the problem.

I have not found the cause of the error so far, however I have found out a workaround, and I hope you find it helpful too:
instead of using CakePHP built-in JSON encode function($javascript->object), I used native php JSON encode function(json_encode), and I need to encode it direct inside my controller action, and that solves the problem. Taking my application as an example, for json_view.ctp, leave it blank, and inside controller action jsonView(), do $jsonData=json_encode($arrayData); echo $jsonData;

If you know the reason which is causing this, do let us know!

admin 1-CakePHP, General Cakephp

Get Adobe Flash playerPlugin by wpburn.com wordpress themes