From 140736a1e49d47376ebc893aa2da250ba3d836a3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 16 Nov 2008 07:14:12 +0000 Subject: Several large changes: 1) Changed the way that we get forms. Now, if you want to get a form for a REST resource you prefix /form to the resource id. So: /form/photo/1 : returns a form for editing photo id 1 /form/comments/1 : returns a form for adding a comment to photo id 1 /form/comment/1 : returns a form for editing comment id 1 2) Changed the comment module to have two controllers: comment: deals with a single comment resource comments: deal with collections of comments attached to an item Related stuff: - Moved the comments js into the theme - Reworked Comment_Helper for clarity - Moved form generation code down into Comment_Helper - Cleaned up routes (eliminating new comment ones added in recent rev) - Added form() function to all REST controllers - Changed comment module to use a block instead of an arbitrary helper call from the theme - Comment controller only returns HTML currently, but returns a 201 Created status code when a new comment is added, which the Ajax code can catch and act upon. - Got rid of a lot of extra views in comment module --- core/controllers/rest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'core/controllers/rest.php') diff --git a/core/controllers/rest.php b/core/controllers/rest.php index 09c85653..4a6c4eb4 100644 --- a/core/controllers/rest.php +++ b/core/controllers/rest.php @@ -39,6 +39,10 @@ * public function _delete(ORM $comment) { * // Handle DELETE request * } + * + * public function form(ORM $comment) { + * // Show a form for creating a new comment + * } * } * * A request to http://example.com/gallery3/comment/3 will result in a call to @@ -85,6 +89,20 @@ abstract class REST_Controller extends Controller { } } + public function form($id) { + if ($this->resource_type == null) { + throw new Exception("@todo ERROR_MISSING_RESOURCE_TYPE"); + } + + // @todo this needs security checks + $resource = ORM::factory($this->resource_type, $id); + if (!$resource->loaded) { + return Kohana::show_404(); + } + + return $this->_form($resource); + } + /** * Perform a GET request on this resource * @param ORM $resource the instance of this resource type @@ -108,4 +126,10 @@ abstract class REST_Controller extends Controller { * @param ORM $resource the instance of this resource type */ abstract public function _delete($resource); + + /** + * Present a form for adding a new resource + * @param ORM $resource the resource container for instances of this resource type + */ + abstract public function _form($resource); } -- cgit v1.2.3