mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
cfbc43671e
- Adding RequestHandler to the error controller. This allows reuse of all of Cake's internals. - Adding a simple JsonView class to do serialized JSON views. - Adding serialize hooks, and wiring things together.
27 lines
732 B
PHP
27 lines
732 B
PHP
<?php
|
|
|
|
class JsonView extends View {
|
|
|
|
/**
|
|
* Render a JSON view.
|
|
*
|
|
* 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,
|
|
* and use a normal view + layout as well.
|
|
*
|
|
* @param string $view The view being rendered.
|
|
* @param string $layout The layout being rendered.
|
|
* @return The rendered view.
|
|
*/
|
|
public function render($view = null, $layout = null) {
|
|
if (isset($this->viewVars['serialize'])) {
|
|
$vars = array_intersect_key(
|
|
$this->viewVars,
|
|
array_flip($this->viewVars['serialize'])
|
|
);
|
|
return json_encode($vars);
|
|
}
|
|
return parent::render($view, $layout);
|
|
}
|
|
}
|