diff options
Diffstat (limited to 'poc/poc02-compiling-cake/src/workdir/in/app/Controller/PostsController.php')
-rw-r--r-- | poc/poc02-compiling-cake/src/workdir/in/app/Controller/PostsController.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/poc/poc02-compiling-cake/src/workdir/in/app/Controller/PostsController.php b/poc/poc02-compiling-cake/src/workdir/in/app/Controller/PostsController.php new file mode 100644 index 0000000..c6ff3d2 --- /dev/null +++ b/poc/poc02-compiling-cake/src/workdir/in/app/Controller/PostsController.php @@ -0,0 +1,48 @@ +<?php +class PostsController extends AppController { + public $helpers = array('Html', 'Form'); + + public function index() { + $this->set('posts', $this->Post->find('all')); + } + + public function view($id = null) { + $this->Post->id = $id; + $this->set('post', $this->Post->read()); + } + + public function add() { + if ($this->request->is('post')) { + if ($this->Post->save($this->request->data)) { + $this->Session->setFlash('Your post has been saved.'); + $this->redirect(array('action' => 'index')); + } else { + $this->Session->setFlash('Unable to add your post.'); + } + } + } + + public function edit($id = null) { + $this->Post->id = $id; + if ($this->request->is('get')) { + $this->request->data = $this->Post->read(); + } else { + if ($this->Post->save($this->request->data)) { + $this->Session->setFlash('Your post has been updated.'); + $this->redirect(array('action' => 'index')); + } else { + $this->Session->setFlash('Unable to update your post.'); + } + } + } + + public function delete($id) { + if ($this->request->is('get')) { + throw new MethodNotAllowedException(); + } + if ($this->Post->delete($id)) { + $this->Session->setFlash('The post with id: ' . $id . ' has been deleted.'); + $this->redirect(array('action' => 'index')); + } + } +} |