Index: documentation/manual/en/module_specs/Zend_Controller-ActionHelpers-Json.xml
===================================================================
--- documentation/manual/en/module_specs/Zend_Controller-ActionHelpers-Json.xml (revision 24517)
+++ documentation/manual/en/module_specs/Zend_Controller-ActionHelpers-Json.xml (working copy)
@@ -10,57 +10,125 @@
execution.
-
- The JSON action helper does several things:
-
+
+ Usage
-
-
-
- Disables layouts if currently enabled.
-
-
+
+ Usage is simple: either call it as a method of the helper broker, or
+ call one of the methods encodeJson() or
+ sendJson():
+
-
+
+ direct($data, $sendNow = true, $keepLayouts = false, $encodeData = true)
+
+
+
+ sendJson($data, $keepLayouts = false, $encodeData = true)
+
+
+
+ encodeJson($data, $keepLayouts = false, $encodeData = true)
+
+
+
+
+
+ $data: data to encode as JSON
+
+
+
+
+ $sendNow: flag to define whether
+ to send the JSON data immediately. When true, the helper
+ will immediately set the respose body and exit.
+
+
+
+
+ $keepLayouts: flag to define whether
+ to enable or disable layours. When false, all layouts
+ are disabled. Optionally, this can be an array of options
+ to pass as the second argument to Zend_Json::encode().
+ This array of options allows enabling layouts and encoding using
+ Zend_Json_Expr.
+
+
+
+
+ $encodeData: flag to define whether
+ $data is already JSON-encoded. When
+ true, this helper will not encode $data
+ to JSON before sending.
+
+
+
+
+
+ Keeping Layouts
+
- Optionally, an array of options to pass as the second argument
- to Zend_Json::encode(). This array of options
- allows enabling layouts and encoding using
- Zend_Json_Expr.
+ If you have a separate layout for JSON responses -- perhaps to wrap
+ the JSON response in some sort of context -- each method in the
+ JSON helper accepts an optional argument $keepLayouts: a flag to enable or
+ disable layouts. Passing a boolean TRUE value will keep
+ layouts enabled:
_helper->json($data, array('enableJsonExprFinder' => true));
+$this->_helper->json($data, true);
]]>
-
-
- Disables the ViewRenderer if currently enabled.
+ Optionally, you can pass an array as the third parameter. This
+ array may contain a variety of options, including the
+ keepLayouts option:
-
-
+ _helper->json($data, true, array('keepLayouts' => true);
+
+// ...or, call a method of the helper
+$this->_helper->sendJson($data, array('keepLayouts' => true));
+]]>
+
+
+
+ Enabling encoding using Zend_Json_Expr
+
- Sets the 'Content-Type' response header to 'application/json'.
+ Zend_Json::encode() allows the encoding of native
+ JSON expressions using Zend_Json_Expr
+ objects. This option is disabled by default. To enable this option, pass a boolean
+ TRUE value to the enableJsonExprFinder
+ option:
-
-
+ _helper->json($data, true, array('enableJsonExprFinder' => true);
+]]>
+
- By default, immediately returns the response, without waiting
- for the action to finish execution.
+ If you desire to do this, you must pass an
+ array as the third argument. This also allows you to combine other
+ options, such as the keepLayouts option. All such
+ options are then passed to Zend_Json::encode().
-
-
-
- Usage is simple: either call it as a method of the helper broker, or
- call one of the methods encodeJson() or
- sendJson():
-
+ _helper->json($data, true, array(
+'enableJsonExprFinder' => true,
+'keepLayouts' => true,
+));
+]]>
+
+
-
+ Example
+
+
-
-
- Keeping Layouts
-
-
- If you have a separate layout for JSON responses -- perhaps to wrap
- the JSON response in some sort of context -- each method in the
- JSON helper accepts a second, optional argument: a flag to enable or
- disable layouts. Passing a boolean TRUE value will keep
- layouts enabled:
-
-
- _helper->json($data, true);
-]]>
-
-
- Optionally, you can pass an array as the second parameter. This
- array may contain a variety of options, including the
- keepLayouts option:
-
-
- _helper->json($data, array('keepLayouts' => true);
-]]>
-
-
-
- Enabling encoding using Zend_Json_Expr
-
-
- Zend_Json::encode() allows the encoding of native
- JSON expressions using Zend_Json_Expr
- objects. This option is disabled by default. To enable this option, pass a boolean
- TRUE value to the enableJsonExprFinder
- option:
-
-
- _helper->json($data, array('enableJsonExprFinder' => true);
-]]>
-
-
- If you desire to do this, you must pass an
- array as the second argument. This also allows you to combine other
- options, such as the keepLayouts option. All such
- options are then passed to Zend_Json::encode().
-
-
- _helper->json($data, array(
- 'enableJsonExprFinder' => true,
- 'keepLayouts' => true,
-));
-]]>
-
+
+
+