Zend Framework Action Assistant JSON Usage Example analysis, zendjson_php tutorial

Source: Internet
Author: User
Tags zend framework

Zend Framework Action Assistant JSON Usage example analysis, Zendjson


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.

Articles you may be interested in:

    • Controller usage Analysis of MVC Framework for Zend Framework Tutorial
    • Zend Framework Tutorial's routing function zend_controller_router detailed
    • Zend Framework Tutorial Zend_controller_plugin plugin Usage
    • Package Zend_controller_response Example of response object for Zend Framework tutorial
    • Package Zend_controller_request example of request object for Zend Framework tutorial
    • Zend Framework Tutorial Action base class Zend_controller_action detailed
    • Zend Framework Tutorial Distributor Zend_controller_dispatcher Usage
    • Zend Framework Tutorial Front Controller Zend_controller_front Usage
    • Zend Framework Action Assistant Redirector usage examples
    • Zend Framework Action Helper URL usage detailed
    • Zend Framework Action Assistant Flashmessenger usage
    • Examples of resource autoloading usages of the Zend framework tutorial

http://www.bkjia.com/PHPjc/1106899.html www.bkjia.com true http://www.bkjia.com/PHPjc/1106899.html techarticle Zend Framework Action Assistant JSON Usage example analysis, Zendjson This article describes the Zend Framework action Assistant JSON usage. Share to everyone for your reference, as follows: Use of JSON ...

  • Related Article

    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.