summaryrefslogtreecommitdiff
path: root/modules/comment/controllers/comment.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-11-17 00:30:18 +0000
committerBharat Mediratta <bharat@menalto.com>2008-11-17 00:30:18 +0000
commitc91e90406bbc81f8311a1d2707dd141d150f99a4 (patch)
treeddda2c6bacd4b0e0e30f4c8a62d13b2842b864cc /modules/comment/controllers/comment.php
parent0975e702a99dad701f66c606de6597048338f247 (diff)
Add output formats to our REST controllers. Add support for JSON and
XML to the comment controllers as a proof of concept. It's not fully baked; we should examine ways to create helpers to make this process easier.
Diffstat (limited to 'modules/comment/controllers/comment.php')
-rw-r--r--modules/comment/controllers/comment.php23
1 files changed, 17 insertions, 6 deletions
diff --git a/modules/comment/controllers/comment.php b/modules/comment/controllers/comment.php
index 9a9ce84e..546f3d67 100644
--- a/modules/comment/controllers/comment.php
+++ b/modules/comment/controllers/comment.php
@@ -31,14 +31,26 @@ class Comment_Controller extends REST_Controller {
/**
* Get an existing comment.
- * @see Rest_Controller::_get($resource)
+ * @see Rest_Controller::_get($resource, $output_format)
*/
- public function _get($comment) {
- $v = new View("comment.html");
- $v->comment = $comment;
- print $v;
+ public function _get($comment, $output_format) {
+ switch ($output_format) {
+ case "xml":
+ print xml::to_xml($comment->as_array(), array("comment"));
+ break;
+
+ case "json":
+ print json_encode($comment->as_array());
+ break;
+
+ default:
+ $v = new View("comment.$output_format");
+ $v->comment = $comment;
+ print $v;
+ }
}
+
/**
* Update existing comment.
* @see Rest_Controller::_put($resource)
@@ -46,7 +58,6 @@ class Comment_Controller extends REST_Controller {
public function _put($comment) {
$form = comment::get_edit_form($comment);
if ($form->validate()) {
- $comment = ORM::factory('comment');
$comment->author = $this->input->post('author');
$comment->email = $this->input->post('email');
$comment->text = $this->input->post('text');