Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting content type specific error pages.
- 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.
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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); | ||
} | ||
} |