/Controller/CategoriesController.php

https://github.com/Wargo/reddevil · PHP · 52 lines · 29 code · 23 blank · 0 comment · 5 complexity · 2b6f711426db185a2659728440be7df0 MD5 · raw file

  1. <?php
  2. class CategoriesController extends AppController {
  3. function admin_index() {
  4. $categories = $this->Category->find('all');
  5. $this->set(compact('categories'));
  6. }
  7. function admin_edit($id = null) {
  8. if ($this->request->data) {
  9. if ($id) {
  10. $this->Category->id = $id;
  11. } else {
  12. $this->Category->create();
  13. }
  14. $this->request->data['Category']['slug'] = ClassRegistry::init('Video')->title2url($this->request->data['Category']['name']);
  15. $this->Category->save($this->request->data);
  16. return $this->redirect('index');
  17. }
  18. if ($id) {
  19. $this->request->data = $this->Category->findById($id);
  20. }
  21. $this->set(compact('id'));
  22. }
  23. function admin_delete($id = null) {
  24. if ($id) {
  25. $this->Category->delete($id);
  26. }
  27. return $this->redirect('index');
  28. }
  29. }