ZendFramework action assistant Json usage instance analysis, zendjson_PHP tutorial

Source: Internet
Author: User
ZendFramework action assistant Json usage instance analysis, zendjson. ZendFramework action assistant Json usage example analysis, zendjson this article describes the ZendFramework action assistant Json usage. For your reference, the details are as follows: Analysis of Zend Framework action assistant Json usage examples in Json, zendjson

This example describes how to use Zend Framework action assistant Json. We will share this with you for your reference. The details are as follows:

Json is easy to use. The following describes how to use Json:

Json is used to decode and send JSON responses;

When processing an AJAX request that expects the data table to respond, the JSON response quickly becomes the selected response.

JSON can be parsed on the client immediately for fast execution.

The JSON action Assistant completes the following tasks:

If the layout is enabled, disable it.

If the view parser 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 a response immediately.

The usage is very simple: call it as a helper 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: Keeping Layouts)

If you have a separate layout for the JSON response-you may encapsulate JSON into some contexts-each method in the JSON assistant accepts the Second Optional parameter: enable or disable the layout 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);  }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.