Change serialize to _serialize

Its possible that a developer would use 'serialize' as a legitimate
view variable.  Prefix with an _ to minimize that.
This commit is contained in:
mark_story 2011-11-22 20:56:25 -05:00
parent 04463c4ee5
commit 6e1b1df2b2
4 changed files with 24 additions and 24 deletions

View file

@ -16,31 +16,31 @@ App::uses('View', 'View');
/**
* A view class that is used for JSON responses.
*
* By setting the 'serialize' key in your controller, you can specify a view variable
* By setting the '_serialize' key in your controller, you can specify a view variable
* that should be serialized to JSON and used as the response for the request.
* This allows you to omit views + layouts, if your just need to emit a single view
* variable as the JSON response.
*
* In your controller, you could do the following:
*
* `$this->set(array('posts' => $posts, 'serialize' => 'posts'));`
* `$this->set(array('posts' => $posts, '_serialize' => 'posts'));`
*
* When the view is rendered, the `$posts` view variable will be serialized
* into JSON.
*
* You can also define `'serialize'` as an array. This will create a top level object containing
* You can also define `'_serialize'` as an array. This will create a top level object containing
* all the named view variables:
*
* {{{
* $this->set(compact('posts', 'users', 'stuff'));
* $this->set('serialize', array('posts', 'users'));
* $this->set('_serialize', array('posts', 'users'));
* }}}
*
* The above would generate a JSON object that looks like:
*
* `{"posts": [...], "users": [...]}`
*
* If you don't use the `serialize` key, you will need a view. You can use extended
* If you don't use the `_serialize` key, you will need a view. You can use extended
* views to provide layout like functionality.
*
* @package Cake.View
@ -73,9 +73,9 @@ class JsonView extends View {
/**
* Render a JSON view.
*
* Uses the special 'serialize' parameter to convert a set of
* Uses the special '_serialize' parameter to convert a set of
* view variables into a JSON response. Makes generating simple
* JSON responses very easy. You can omit the 'serialize' parameter,
* JSON responses very easy. You can omit the '_serialize' parameter,
* and use a normal view + layout as well.
*
* @param string $view The view being rendered.
@ -83,8 +83,8 @@ class JsonView extends View {
* @return string The rendered view.
*/
public function render($view = null, $layout = null) {
if (isset($this->viewVars['serialize'])) {
$serialize = $this->viewVars['serialize'];
if (isset($this->viewVars['_serialize'])) {
$serialize = $this->viewVars['_serialize'];
if (is_array($serialize)) {
$data = array();
foreach ($serialize as $key) {