Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <!-- File: /Blog/controllers/posts_controller -->
  2. <?php
  3. class PostsController extends AppController {
  4. var $name = 'Posts';
  5. function index() {
  6. $this->set('posts', $this->Post->find('all'));
  7. }
  8. function view($id = null) {
  9. $this->Post->id = $id;
  10. $this->set('post', $this->Post->read());
  11. }
  12. function add() {
  13. if (!empty($this->data)) {
  14. if ($this->Post->save($this->data)) {
  15. $this->Session->setFlash('Your post has been saved.');
  16. $this->redirect(array('action'=>'index'));
  17. }
  18. }
  19. }
  20. function edit($id=null) {
  21. $this->Post->id=$id;
  22. if (empty($this->data)) {
  23. $this->data = $this->Post->read();
  24. } else {
  25. if ($this->Post->save($this->data)) {
  26. $this->Session->setFlash('Your post has been updated.');
  27. $this->redirect(array('action'=>'index', null, true));
  28. exit();
  29. }
  30.  
  31. }
  32.  
  33. }
  34. function delete($id) {
  35. $this->Post->delete($id);
  36. $this->Session->setFlash('The post with id: '. $id .'has been deleted' );
  37. $this->redirect(array('action'=>'index', null ,true));
  38. exit();
  39. }
  40. }
  41. ?>
Add Comment
Please, Sign In to add comment