PageRenderTime 23ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/app/controllers/links_controller.php

https://github.com/hardsshah/bookmarks
PHP | 68 lines | 61 code | 7 blank | 0 comment | 12 complexity | 3a8f9060b76aaf5462d51e638e0570f2 MD5 | raw file
  1. <?php
  2. class LinksController extends AppController {
  3. var $name = 'Links';
  4. var $helpers = array('Html', 'Form');
  5. var $viewPath = '_templates';
  6. var $paginate = array('limit' => 20);
  7. function index() {
  8. $this->Link->recursive = 0;
  9. $this->set('links', $this->paginate());
  10. }
  11. function view($id = null) {
  12. if (!$id) {
  13. $this->Session->setFlash(__('Invalid Link.', true));
  14. $this->redirect(array('action'=>'index'));
  15. }
  16. $this->set('link', $this->Link->read(null, $id));
  17. }
  18. function add() {
  19. if (!empty($this->data)) {
  20. $this->Link->create();
  21. if ($this->Link->save($this->data)) {
  22. $this->Session->setFlash(__('The Link has been saved', true));
  23. $this->redirect(array('action'=>'index'));
  24. } else {
  25. $this->Session->setFlash(__('The Link could not be saved. Please, try again.', true));
  26. }
  27. }
  28. $linkCategories = $this->Link->LinkCategory->find('list');
  29. $this->set(compact('linkCategories'));
  30. }
  31. function edit($id = null) {
  32. if (!$id && empty($this->data)) {
  33. $this->Session->setFlash(__('Invalid Link', true));
  34. $this->redirect(array('action'=>'index'));
  35. }
  36. if (!empty($this->data)) {
  37. if ($this->Link->save($this->data)) {
  38. $this->Session->setFlash(__('The Link has been saved', true));
  39. $this->redirect(array('action'=>'index'));
  40. } else {
  41. $this->Session->setFlash(__('The Link could not be saved. Please, try again.', true));
  42. }
  43. }
  44. if (empty($this->data)) {
  45. $this->data = $this->Link->read(null, $id);
  46. }
  47. $linkCategories = $this->Link->LinkCategory->find('list');
  48. $this->set(compact('linkCategories'));
  49. }
  50. function delete($id = null) {
  51. if (!$id) {
  52. $this->Session->setFlash(__('Invalid id for Link', true));
  53. $this->redirect(array('action'=>'index'));
  54. }
  55. if ($this->Link->del($id)) {
  56. $this->Session->setFlash(__('Link deleted', true));
  57. $this->redirect(array('action'=>'index'));
  58. }
  59. }
  60. }
  61. ?>