Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

http://book.cakephp.org/view/337/adding-posts

  • Loading branch information...
commit 30a27eb0b91ad9495f7400b78b15e1978448cf82 1 parent 9387374
@mariuz authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 app/controllers/posts_controller.php
View
14 app/controllers/posts_controller.php
@@ -1,15 +1,23 @@
<?php
class PostsController extends AppController {
-
var $name = 'Posts';
function index() {
- $this->set('posts', $this->Post->find('all'));
+ $this->set('posts', $this->Post->find('all'));
}
- function view($id = null) {
+ function view($id) {
$this->Post->id = $id;
$this->set('post', $this->Post->read());
+
+ }
+
+ function add() {
+ if (!empty($this->data)) {
+ if ($this->Post->save($this->data)) {
+ $this->flash('Your post has been saved.', '/posts');
+ }
+ }
}
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.