@@ -85,20 +85,7 @@ public function __construct(Controller $controller = null) {
85
85
*/
86
86
public function render ($ view = null , $ layout = null ) {
87
87
if (isset ($ this ->viewVars ['_serialize ' ])) {
88
- $ serialize = $ this ->viewVars ['_serialize ' ];
89
- if (is_array ($ serialize )) {
90
- $ data = array ('response ' => array ());
91
- foreach ($ serialize as $ key ) {
92
- $ data ['response ' ][$ key ] = $ this ->viewVars [$ key ];
93
- }
94
- } else {
95
- $ data = isset ($ this ->viewVars [$ serialize ]) ? $ this ->viewVars [$ serialize ] : null ;
96
- if (is_array ($ data ) && Set::numeric (array_keys ($ data ))) {
97
- $ data = array ('response ' => array ($ serialize => $ data ));
98
- }
99
- }
100
- $ content = Xml::fromArray ($ data )->asXML ();
101
- return $ content ;
88
+ return $ this ->_serialize ($ this ->viewVars ['_serialize ' ]);
102
89
}
103
90
if ($ view !== false && $ viewFileName = $ this ->_getViewFileName ($ view )) {
104
91
if (!$ this ->_helpersLoaded ) {
@@ -110,4 +97,25 @@ public function render($view = null, $layout = null) {
110
97
}
111
98
}
112
99
100
+ /**
101
+ * Serialize view vars
102
+ *
103
+ * @param array $serialize The viewVars that need to be serialized
104
+ * @return string The serialized data
105
+ */
106
+ protected function _serialize ($ serialize ) {
107
+ if (is_array ($ serialize )) {
108
+ $ data = array ('response ' => array ());
109
+ foreach ($ serialize as $ key ) {
110
+ $ data ['response ' ][$ key ] = $ this ->viewVars [$ key ];
111
+ }
112
+ } else {
113
+ $ data = isset ($ this ->viewVars [$ serialize ]) ? $ this ->viewVars [$ serialize ] : null ;
114
+ if (is_array ($ data ) && Set::numeric (array_keys ($ data ))) {
115
+ $ data = array ('response ' => array ($ serialize => $ data ));
116
+ }
117
+ }
118
+ return Xml::fromArray ($ data )->asXML ();
119
+ }
120
+
113
121
}
0 commit comments