This example describes the Zend Framework action Assistant JSON usage. Share to everyone for your reference, specific as follows:
The use of JSON is simpler, and the following are the instructions given by the document:
JSON is used to decode and send JSON responses;
When processing an AJAX request for an expected datasheet response, the JSON response quickly becomes the selected response.
JSON can be resolved immediately at the client, allowing for rapid execution.
The JSON action Assistant completes the following tasks:
If the layout is open (enabled), close (disable) it.
If the View parser (Viewrenderer) is open, close it.
Set the ' Content-type ' response header to ' Application/json '.
By default, you do not need to wait for the action to complete and return the response immediately.
The usage is simple: either call it as an assistant proxy method, or call one of the Encodejson () and Sendjson () methods:
Class Foocontroller extends zend_controller_action
{public
function baraction ()
{
//do some
processing ... Send the JSON response:
$this->_helper->json ($data);
Or ...
$this->_helper->json->sendjson ($data);
Or retrieve the JSON:
$json = $this->_helper->json->encodejson ($data);
}
Note: Keep layout (keeping Layouts)
If you have a separate layout for the JSON response-perhaps to encapsulate JSON in some context-accept the second optional argument in each method of the JSON helper: turning on or off the layout's flag, passing a Boolean true value will keep the layout open:
Class Foocontroller extends zend_controller_action
{public
function baraction ()
{
//Retrieve the JSON, keeping layouts:
$json = $this->_helper->json->encodejson ($data, True);
}
More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.