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 @@ +

Add Post

+Form->create("Post"); +echo $this->Form->input("title"); +echo $this->Form->input("body", array("rows" => "3")); +echo $this->Form->end("Save Post"); +?> diff --git a/web-cake/html/app/views/posts/edit.ctp b/web-cake/html/app/views/posts/edit.ctp new file mode 100644 index 0000000..07d359a --- /dev/null +++ b/web-cake/html/app/views/posts/edit.ctp @@ -0,0 +1,8 @@ +

Edit Post

+Form->create("Post", array("action" => "edit")); +echo $this->Form->input("title"); +echo $this->Form->input("body", array("rows" => "3")); +echo $this->Form->input("id", array("type" => "hidden")); +echo $this->Form->end("Save Post"); +?> diff --git a/web-cake/html/app/views/posts/index.ctp b/web-cake/html/app/views/posts/index.ctp new file mode 100644 index 0000000..598445b --- /dev/null +++ b/web-cake/html/app/views/posts/index.ctp @@ -0,0 +1,40 @@ +

Blog posts

+Html->link( + "Add Post", array("controller" => "posts", "action" => "add") +); +?> + + + + + + + + + + + + + + + + + +
IdTitleActionsCreated
+ 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"]) + ); + ?> +
diff --git a/web-cake/html/app/views/posts/view.ctp b/web-cake/html/app/views/posts/view.ctp new file mode 100644 index 0000000..363812b --- /dev/null +++ b/web-cake/html/app/views/posts/view.ctp @@ -0,0 +1,3 @@ +

+

Created:

+