PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/app/Controller/ArticlesTagsController.php

https://github.com/Bancha/cakephp
PHP | 100 lines | 62 code | 6 blank | 32 comment | 13 complexity | 94a4350c338aa0eca7f3fc14720f8da8 MD5 | raw file
  1. <?php
  2. /**
  3. * ArticlesTags Controller
  4. *
  5. */
  6. class ArticlesTagsController extends AppController {
  7. /**
  8. * index method
  9. *
  10. * @return void
  11. */
  12. public function index() {
  13. $this->ArticlesTag->recursive = 0;
  14. $this->set('articlesTags', $this->paginate());
  15. }
  16. /**
  17. * view method
  18. *
  19. * @param string $id
  20. * @return void
  21. */
  22. public function view($id = null) {
  23. $this->ArticlesTag->id = $id;
  24. if (!$this->ArticlesTag->exists()) {
  25. throw new NotFoundException(__('Invalid articles tag'));
  26. }
  27. $this->set('articlesTag', $this->ArticlesTag->read(null, $id));
  28. }
  29. /**
  30. * add method
  31. *
  32. * @return void
  33. */
  34. public function add() {
  35. if ($this->request->is('post')) {
  36. $this->ArticlesTag->create();
  37. if ($this->ArticlesTag->save($this->request->data)) {
  38. $this->Session->setFlash(__('The articles tag has been saved'));
  39. $this->redirect(array('action' => 'index'));
  40. } else {
  41. $this->Session->setFlash(__('The articles tag could not be saved. Please, try again.'));
  42. }
  43. }
  44. $articles = $this->ArticlesTag->Article->find('list');
  45. $tags = $this->ArticlesTag->Tag->find('list');
  46. $this->set(compact('articles', 'tags'));
  47. }
  48. /**
  49. * edit method
  50. *
  51. * @param string $id
  52. * @return void
  53. */
  54. public function edit($id = null) {
  55. $this->ArticlesTag->id = $id;
  56. if (!$this->ArticlesTag->exists()) {
  57. throw new NotFoundException(__('Invalid articles tag'));
  58. }
  59. if ($this->request->is('post') || $this->request->is('put')) {
  60. if ($this->ArticlesTag->save($this->request->data)) {
  61. $this->Session->setFlash(__('The articles tag has been saved'));
  62. $this->redirect(array('action' => 'index'));
  63. } else {
  64. $this->Session->setFlash(__('The articles tag could not be saved. Please, try again.'));
  65. }
  66. } else {
  67. $this->request->data = $this->ArticlesTag->read(null, $id);
  68. }
  69. $articles = $this->ArticlesTag->Article->find('list');
  70. $tags = $this->ArticlesTag->Tag->find('list');
  71. $this->set(compact('articles', 'tags'));
  72. }
  73. /**
  74. * delete method
  75. *
  76. * @param string $id
  77. * @return void
  78. */
  79. public function delete($id = null) {
  80. if (!$this->request->is('post')) {
  81. throw new MethodNotAllowedException();
  82. }
  83. $this->ArticlesTag->id = $id;
  84. if (!$this->ArticlesTag->exists()) {
  85. throw new NotFoundException(__('Invalid articles tag'));
  86. }
  87. if ($this->ArticlesTag->delete()) {
  88. $this->Session->setFlash(__('Articles tag deleted'));
  89. $this->redirect(array('action'=>'index'));
  90. }
  91. $this->Session->setFlash(__('Articles tag was not deleted'));
  92. $this->redirect(array('action' => 'index'));
  93. }
  94. }