From b87eee4e49a127c96a58fe1c0e173d9d978edf0a Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 2 Sep 2011 11:38:22 -0430 Subject: [PATCH] Using mapResources for our API --- Config/routes.php | 1 + Controller/CoursesController.php | 6 +++--- View/Layouts/json/default.ctp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Config/routes.php b/Config/routes.php index 7ba3072..c79c815 100755 --- a/Config/routes.php +++ b/Config/routes.php @@ -22,6 +22,7 @@ */ Router::parseExtensions('json'); + Router::mapResources('Courses'); /** * Here, we are connecting '/' (base path) to controller called 'Pages', * its action called 'display', and we pass a param to select the view file diff --git a/Controller/CoursesController.php b/Controller/CoursesController.php index ecc9169..263fe6e 100644 --- a/Controller/CoursesController.php +++ b/Controller/CoursesController.php @@ -7,7 +7,7 @@ class CoursesController extends AppController { public function beforeFilter() { - $this->Auth->allow('index', 'view', 'add'); + $this->Auth->allow('index', 'view'); } /** @@ -68,10 +68,10 @@ public function edit($id = null) { } if ($this->request->is('post') || $this->request->is('put')) { if ($this->Course->save($this->request->data)) { - $this->Session->setFlash(__('The course has been saved')); + $this->Session->setFlash(__('The course has been saved'), 'success'); $this->redirect(array('action' => 'index')); } else { - $this->Session->setFlash(__('The course could not be saved. Please, try again.')); + $this->Session->setFlash(__('The course could not be saved. Please, try again.'), 'error'); } } else { $this->request->data = $this->Course->read(null, $id); diff --git a/View/Layouts/json/default.ctp b/View/Layouts/json/default.ctp index e4db6e4..bcb4c30 100644 --- a/View/Layouts/json/default.ctp +++ b/View/Layouts/json/default.ctp @@ -2,8 +2,8 @@ $status = 'success'; $message = ''; if ($this->Session->check('Message.flash')) { - $status = $this->Session->read('Message.element'); - $message = $this->Session->read('Message.message'); + $status = $this->Session->read('Message.flash.element'); + $message = $this->Session->read('Message.flash.message'); $this->Session->flash(); } $errors = array();