Home >Backend Development >PHP Tutorial >Zend Framework action assistant Json usage example analysis, zendjson_PHP tutorial

Zend Framework action assistant Json usage example analysis, zendjson_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:57:43849browse

Zend Framework action assistant Json usage example analysis, zendjson

This article describes the Zend Framework action assistant Json usage example. Share it with everyone for your reference, the details are as follows:

The use of Json is relatively simple. The following is the usage given in the document:

Json is used to decode and send JSON responses;

When handling AJAX requests that expect a data table response, JSON responses quickly become the response of choice.

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

JSON action assistant completes the following tasks:

If the layout is enabled, disable it.

If the 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 be executed and the response is returned immediately.

Usage is simple: either call it as a method of the helper proxy, 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 - perhaps encapsulating the JSON into some context - each method in the JSON helper accepts a second optional argument: a flag to turn the layout on or off, 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);
  }
}

Readers who are interested in more zend-related content can check out the special topics of this site: "Zend FrameWork Framework Introductory Tutorial", "php Excellent Development Framework Summary", "Yii Framework Introduction and Summary of Common Techniques", "ThinkPHP Introductory Tutorial" , "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • Analysis of Controller Usage of MVC Framework in Zend Framework Tutorial
  • Zend Framework Tutorial Road explained in detail by function Zend_Controller_Router
  • Zend Framework tutorial: Detailed explanation of Zend_Controller_Plugin plug-in usage
  • Zend Framework tutorial: Detailed explanation of the encapsulation of the response object Zend_Controller_Response instance
  • Zend Framework tutorial: Detailed explanation of the encapsulation of the request object Zend_Controller_Request instance
  • Zend Framework tutorial Detailed explanation of the action's base class Zend_Controller_Action
  • Zend Framework tutorial's detailed explanation of the usage of the distributor Zend_Controller_Dispatcher
  • Zend Framework tutorial's detailed explanation of the usage of the front-end controller Zend_Controller_Front
  • Zend Framework action assistant Redirector usage Detailed explanation of examples
  • Zend Framework action assistant Url usage details
  • Zend Framework action assistant FlashMessenger usage details
  • Resource Autoloading usage example of Zend Framework tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1106899.htmlTechArticleZend Framework action assistant Json usage example analysis, zendjson This article describes the Zend Framework action assistant Json usage example. Share it with everyone for your reference, the details are as follows: The use of Json...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn