Zend Framework Action Assistant JSON Usage example Analysis _php instance

Source: Internet
Author: User
Tags zend zend framework

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.

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.