Guest User

Tournament Controller

a guest
Sep 11th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2. class TournamentsController extends AppController {
  3.     public function index() {
  4.         $this->set('tournaments', $this->Tournament->find('all'));
  5.     }
  6.    
  7.     public function add() {
  8.         $Version = ClassRegistry::init('Version');
  9.         $this->set('versions', $Version->find('list'));
  10.        
  11.         if ($this->request->is('post')) {
  12.             $this->request->data['Tournament']['user_id'] = $this->Auth->user('id');
  13.             if ($this->Tournament->save($this->request->data)) {
  14.                 $this->Session->setFlash('The tournament has been saved.');
  15.                 $this->redirect(array('action' => 'index'));
  16.             } else {
  17.                 $this->Session->setFlash('Unable to add the tournament.');
  18.             }
  19.         }
  20.     }
  21.    
  22.     public function edit($id = null) {
  23.         $Version = ClassRegistry::init('Version');
  24.         $this->set('versions', $Version->find('list'));
  25.        
  26.         $this->Tournament->id = $id;
  27.         if ($this->request->is('get')) {
  28.             $this->request->data = $this->Tournament->read();
  29.         } else {
  30.             if ($this->Tournament->save($this->request->data)) {
  31.                 $this->Session->setFlash('The tournament has been updated.');
  32.                 $this->redirect(array('action' => 'index'));
  33.             } else {
  34.                 $this->Session->setFlash('Unable to update the tournament.');
  35.             }
  36.         }
  37.     }
  38.    
  39.     public function delete($id) {
  40.         if ($this->request->is('get')) {
  41.             throw new MethodNotAllowedException();
  42.         }
  43.         if ($this->Tournament->delete($id)) {
  44.             $this->Session->setFlash('The tournament with id: ' . $id . ' has been deleted.');
  45.             $this->redirect(array('action' => 'index'));
  46.         }
  47.     }
  48.    
  49.     public function view($id = null) {     
  50.         $this->Tournament->id = $id;
  51.         $this->set('tournament', $this->Tournament->read());
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment