diff --git a/web-cake/html/app/config/routes.php b/web-cake/html/app/config/routes.php index a186e49..8976535 100644 --- a/web-cake/html/app/config/routes.php +++ b/web-cake/html/app/config/routes.php @@ -26,8 +26,11 @@ * its action called 'display', and we pass a param to select the view file * to use (in this case, /app/views/pages/home.ctp)... */ - Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); + // Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); + Router::connect('/', array('controller' => 'posts', 'action' => 'index')); /** * ...and connect the rest of 'Pages' controller's urls. */ - Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); + Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); + +?> diff --git a/web-cake/html/app/controllers/posts_controller.php b/web-cake/html/app/controllers/posts_controller.php new file mode 100644 index 0000000..8c43305 --- /dev/null +++ b/web-cake/html/app/controllers/posts_controller.php @@ -0,0 +1,47 @@ +set("posts", $this->Post->find("all")); + } + + function view($id = null) { + $this->Post->id = $id; + $this->set("post", $this->Post->read()); + } + + function add() { + if (!empty($this->data)) { + if ($this->Post->save($this->data)) { + $this->Session->setFlash("Your post has been saved."); + $this->redirect(array("action" => "index")); + } + } + } + + function delete($id) { + if ($this->Post->delete($id)) { + $this->Session->setFlash("The post with id: " . $id . " has been deleted"); + $this->redirect(array("action" => "index")); + } + } + + function edit($id = null) { + $this->Post->id = $id; + if (empty($this->data)) { + $this->data = $this->Post->read(); + } else { + if ($this->Post->save($this->data)) { + $this->Session->setFlash("Your post has been updated"); + $this->redirect(array("action" => "index")); + } + } + } + +} + + +?> diff --git a/web-cake/html/app/models/post.php b/web-cake/html/app/models/post.php new file mode 100644 index 0000000..72765ae --- /dev/null +++ b/web-cake/html/app/models/post.php @@ -0,0 +1,15 @@ + array( + "rule" => "notEmpty" + ), + "body" => array( + "rule" => "notEmpty" + ) + ); +} + +?> diff --git a/web-cake/html/app/views/posts/add.ctp b/web-cake/html/app/views/posts/add.ctp new file mode 100644 index 0000000..ff12e32 --- /dev/null +++ b/web-cake/html/app/views/posts/add.ctp @@ -0,0 +1,7 @@ +
Id | +Title | +Actions | +Created | +
---|---|---|---|
+ | + Html->link( + $post["Post"]["title"], + array("controller" => "posts", "action" => "view", + $post["Post"]["id"]) + ); + ?> + | ++ Html->link( + "Delete", array("action" => "delete", $post["Post"]["id"]), + null, "Are you sure?" + ); + ?> + Html->link( + "Edit", array("action" => "edit", $post["Post"]["id"]) + ); + ?> + | ++ |
Created:
+