This example describes the JSON usage of the Zend Framework Action Helper. Share to everyone for your reference, as follows:
The use of JSON is simple, the following is the usage of the document:
JSON is used to decode and send JSON responses;
When processing an AJAX request that expects a data table response, the JSON response quickly becomes the selected response.
JSON can be parsed immediately on the client side for quick execution.
The JSON action Assistant accomplishes the following tasks:
If the layout is open (enabled), then close (disable) it.
If the View resolver (viewrenderer) is open, close it.
Set the ' Content-type ' response header to ' Application/json '.
By default, there is no need to wait for the action to complete and return the response immediately.
The usage is simple: either call it as an assistant agent, 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: Maintain layout (keeping Layouts)
If you have a separate layout for the JSON response-perhaps encapsulating the JSON in some context-each method in the JSON helper accepts the second optional parameter: Open or close the flag of the layout, 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 topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "
I hope this article is helpful to you in PHP programming.