Skip to content

Commit 6e1b1df

Browse files
committed
Change serialize to _serialize
Its possible that a developer would use 'serialize' as a legitimate view variable. Prefix with an _ to minimize that.
1 parent 04463c4 commit 6e1b1df

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

lib/Cake/Test/Case/View/JsonViewTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testRenderWithoutView() {
3939
$Response = new CakeResponse();
4040
$Controller = new Controller($Request, $Response);
4141
$data = array('user' => 'fake', 'list' => array('item1', 'item2'));
42-
$Controller->set(array('data' => $data, 'serialize' => 'data'));
42+
$Controller->set(array('data' => $data, '_serialize' => 'data'));
4343
$View = new JsonView($Controller);
4444
$output = $View->render(false);
4545

@@ -48,7 +48,7 @@ public function testRenderWithoutView() {
4848
}
4949

5050
/**
51-
* Test render with an array in serialize
51+
* Test render with an array in _serialize
5252
*
5353
* @return void
5454
*/
@@ -58,7 +58,7 @@ public function testRenderWithoutViewMultiple() {
5858
$Controller = new Controller($Request, $Response);
5959
$data = array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2'));
6060
$Controller->set($data);
61-
$Controller->set('serialize', array('no', 'user'));
61+
$Controller->set('_serialize', array('no', 'user'));
6262
$View = new JsonView($Controller);
6363
$output = $View->render(false);
6464

lib/Cake/Test/Case/View/XmlViewTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testRenderWithoutView() {
3939
$Response = new CakeResponse();
4040
$Controller = new Controller($Request, $Response);
4141
$data = array('users' => array('user' => array('user1', 'user2')));
42-
$Controller->set(array('users' => $data, 'serialize' => 'users'));
42+
$Controller->set(array('users' => $data, '_serialize' => 'users'));
4343
$View = new XmlView($Controller);
4444
$output = $View->render(false);
4545

@@ -49,7 +49,7 @@ public function testRenderWithoutView() {
4949
}
5050

5151
/**
52-
* Test render with an array in serialize
52+
* Test render with an array in _serialize
5353
*
5454
* @return void
5555
*/
@@ -59,7 +59,7 @@ public function testRenderWithoutViewMultiple() {
5959
$Controller = new Controller($Request, $Response);
6060
$data = array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2'));
6161
$Controller->set($data);
62-
$Controller->set('serialize', array('no', 'user'));
62+
$Controller->set('_serialize', array('no', 'user'));
6363
$View = new XmlView($Controller);
6464
$output = $View->render(false);
6565

lib/Cake/View/JsonView.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@
1616
/**
1717
* A view class that is used for JSON responses.
1818
*
19-
* By setting the 'serialize' key in your controller, you can specify a view variable
19+
* By setting the '_serialize' key in your controller, you can specify a view variable
2020
* that should be serialized to JSON and used as the response for the request.
2121
* This allows you to omit views + layouts, if your just need to emit a single view
2222
* variable as the JSON response.
2323
*
2424
* In your controller, you could do the following:
2525
*
26-
* `$this->set(array('posts' => $posts, 'serialize' => 'posts'));`
26+
* `$this->set(array('posts' => $posts, '_serialize' => 'posts'));`
2727
*
2828
* When the view is rendered, the `$posts` view variable will be serialized
2929
* into JSON.
3030
*
31-
* You can also define `'serialize'` as an array. This will create a top level object containing
31+
* You can also define `'_serialize'` as an array. This will create a top level object containing
3232
* all the named view variables:
3333
*
3434
* {{{
3535
* $this->set(compact('posts', 'users', 'stuff'));
36-
* $this->set('serialize', array('posts', 'users'));
36+
* $this->set('_serialize', array('posts', 'users'));
3737
* }}}
3838
*
3939
* The above would generate a JSON object that looks like:
4040
*
4141
* `{"posts": [...], "users": [...]}`
4242
*
43-
* If you don't use the `serialize` key, you will need a view. You can use extended
43+
* If you don't use the `_serialize` key, you will need a view. You can use extended
4444
* views to provide layout like functionality.
4545
*
4646
* @package Cake.View
@@ -73,18 +73,18 @@ public function __construct($controller) {
7373
/**
7474
* Render a JSON view.
7575
*
76-
* Uses the special 'serialize' parameter to convert a set of
76+
* Uses the special '_serialize' parameter to convert a set of
7777
* view variables into a JSON response. Makes generating simple
78-
* JSON responses very easy. You can omit the 'serialize' parameter,
78+
* JSON responses very easy. You can omit the '_serialize' parameter,
7979
* and use a normal view + layout as well.
8080
*
8181
* @param string $view The view being rendered.
8282
* @param string $layout The layout being rendered.
8383
* @return string The rendered view.
8484
*/
8585
public function render($view = null, $layout = null) {
86-
if (isset($this->viewVars['serialize'])) {
87-
$serialize = $this->viewVars['serialize'];
86+
if (isset($this->viewVars['_serialize'])) {
87+
$serialize = $this->viewVars['_serialize'];
8888
if (is_array($serialize)) {
8989
$data = array();
9090
foreach ($serialize as $key) {

lib/Cake/View/XmlView.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,33 @@
1717
/**
1818
* A view class that is used for creating XML responses.
1919
*
20-
* By setting the 'serialize' key in your controller, you can specify a view variable
20+
* By setting the '_serialize' key in your controller, you can specify a view variable
2121
* that should be serialized to XML and used as the response for the request.
2222
* This allows you to omit views + layouts, if your just need to emit a single view
2323
* variable as the XML response.
2424
*
2525
* In your controller, you could do the following:
2626
*
27-
* `$this->set(array('posts' => $posts, 'serialize' => 'posts'));`
27+
* `$this->set(array('posts' => $posts, '_serialize' => 'posts'));`
2828
*
2929
* When the view is rendered, the `$posts` view variable will be serialized
3030
* into XML.
3131
*
3232
* **Note** The view variable you specify must be compatible with Xml::fromArray().
3333
*
34-
* You can also define `'serialize'` as an array. This will create an additional
34+
* You can also define `'_serialize'` as an array. This will create an additional
3535
* top level element named `<response>` containing all the named view variables:
3636
*
3737
* {{{
3838
* $this->set(compact('posts', 'users', 'stuff'));
39-
* $this->set('serialize', array('posts', 'users'));
39+
* $this->set('_serialize', array('posts', 'users'));
4040
* }}}
4141
*
4242
* The above would generate a XML object that looks like:
4343
*
4444
* `<response><posts>...</posts><users>...</users></response>`
4545
*
46-
* If you don't use the `serialize` key, you will need a view. You can use extended
46+
* If you don't use the `_serialize` key, you will need a view. You can use extended
4747
* views to provide layout like functionality.
4848
*
4949
* @package Cake.View
@@ -74,18 +74,18 @@ public function __construct($controller) {
7474
/**
7575
* Render a XML view.
7676
*
77-
* Uses the special 'serialize' parameter to convert a set of
77+
* Uses the special '_serialize' parameter to convert a set of
7878
* view variables into a XML response. Makes generating simple
79-
* XML responses very easy. You can omit the 'serialize' parameter,
79+
* XML responses very easy. You can omit the '_serialize' parameter,
8080
* and use a normal view + layout as well.
8181
*
8282
* @param string $view The view being rendered.
8383
* @param string $layout The layout being rendered.
8484
* @return string The rendered view.
8585
*/
8686
public function render($view = null, $layout = null) {
87-
if (isset($this->viewVars['serialize'])) {
88-
$serialize = $this->viewVars['serialize'];
87+
if (isset($this->viewVars['_serialize'])) {
88+
$serialize = $this->viewVars['_serialize'];
8989
if (is_array($serialize)) {
9090
$data = array('response' => array());
9191
foreach ($serialize as $key) {

0 commit comments

Comments
 (0)