From 3ebb751cda5d47147a5c828b4cb32ecd4a9f8042 Mon Sep 17 00:00:00 2001 From: Jozef Selesi Date: Tue, 18 Nov 2008 08:28:32 +0000 Subject: First iteration of REST controller refactoring. RESTful controllers that refer to collections should now have plural names and there should be only one controller per resource. Updated existing classes that implement REST_Controller. The routing now works like this: GET /controller -> controller::_index() POST /controller -> controller::_create() GET /controller/id -> controller::_show() PUT /controller/id -> controller::_update() DELETE /controller/id -> controller::_delete() GET /form/edit/controller/resource_id -> controller::_form() GET /form/add/controller/data -> controller::_form() --- modules/user/controllers/users.php | 46 ++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'modules/user/controllers') diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index 5b438de9..ea3a4c8b 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -21,25 +21,31 @@ class Users_Controller extends REST_Controller { protected $resource_type = "user"; /** - * Present a form for editing a user - * @see Rest_Controller::form($resource) + * Display comments based on criteria. + * @see Rest_Controller::_delete($resource) */ - public function _form($user) { - $form = user::get_edit_form($user); - print $form; + public function _index($query) { + throw new Exception("@todo Comment_Controller::_index NOT IMPLEMENTED"); + } + + /** + * @see Rest_Controller::_create($resource) + */ + public function _create($user) { + throw new Exception("@todo User_Controller::_create NOT IMPLEMENTED"); } /** - * @see Rest_Controller::_get($resource, $format) + * @see Rest_Controller::_show($resource, $format) */ - public function _get($user, $format) { - throw new Exception("@todo User_Controller::_get NOT IMPLEMENTED"); + public function _show($user, $format) { + throw new Exception("@todo User_Controller::_show NOT IMPLEMENTED"); } /** - * @see Rest_Controller::_put($resource) + * @see Rest_Controller::_update($resource) */ - public function _put($user) { + public function _update($user) { $form = user::get_edit_form($user); if ($form->validate()) { foreach ($form->as_array() as $key => $value) { @@ -55,16 +61,22 @@ class Users_Controller extends REST_Controller { } /** - * @see Rest_Controller::_post($resource) + * @see Rest_Controller::_delete($resource) */ - public function _post($user) { - throw new Exception("@todo User_Controller::_post NOT IMPLEMENTED"); + public function _delete($user) { + throw new Exception("@todo User_Controller::_delete NOT IMPLEMENTED"); } /** - * @see Rest_Controller::_delete($resource) + * Present a form for editing a user + * @see Rest_Controller::form($resource) */ - public function _delete($user) { - throw new Exception("@todo User_Controller::_delete NOT IMPLEMENTED"); + public function _form($user, $form_type) { + if ($form_type == "edit") { + $form = user::get_edit_form($user); + print $form; + } else { + return Kohana::show_404(); + } } -} \ No newline at end of file +} -- cgit v1.2.3