04.08 php saved
teknix_
Tags add more
auth  
Note
This is the error i get.
Fatal error: Can't use method return value in write context in C:\wamp\www\cake1.2\app\controllers\films_controller.php on line 74

what am i doing wrong ?
  1. <?php
  2. class FilmsController extends AppController {
  3.  
  4.     var $name = 'Films';
  5.     var $helpers = array('Html', 'Form', 'Zipcode', 'Session');
  6.     var $components = array('Auth');
  7.    
  8.     function beforeFilter() {
  9.         $this->Auth->allow('view', 'index');
  10.         }
  11.        
  12.     function isAuthorized() {
  13.         if ($this->action == ‘edit’) {
  14.             if ($this->Auth->user(‘id’) == $this->data['Film']['user_id']) {
  15.                return true;
  16.           } else {
  17.                return false;
  18.           }
  19.         }
  20.        return true;
  21.     }
  22.  
  23.     function index() {
  24.         $this->Film->recursive = 0;
  25.         $this->set('films', $this->paginate());
  26.     }
  27.  
  28.     function view($id = null) {
  29.         if (!$id) {
  30.             $this->Session->setFlash(__('Invalid Film.', true));
  31.             $this->redirect(array('action'=>'index'));
  32.         }
  33.         $this->set('film', $this->Film->read(null, $id));
  34.     }
  35.  
  36.     function add() {
  37.         if (!empty($this->data)) {
  38.             $this->data['Film']['user_id'] = $this->Auth->user('id');
  39.             $this->Film->create();
  40.             if (!empty($this->data['Film']['file']['tmp_name'])) {
  41.               $fileName = $this->Film->generateUniqueFilename($this->data['Film']['file']['name']);
  42.               //echo 'The filename is:'. $fileName;
  43.               $error = $this->Film->handleFileUpload($this->data['Film']['file'], $fileName);
  44.               //echo 'The error is:'. $error;
  45.                 }
  46.             if (!$error)    {
  47.                 WWW_ROOT.'/files/'.
  48.                 $this->data['Film']['file'] = "/files/".$fileName;
  49.                 
  50.             if ($this->Film->save($this->data)) {
  51.                 $this->Session->setFlash(__('The Film has been saved', true));
  52.                 $this->redirect(array('action'=>'index'));
  53.             } else {
  54.                 $this->Session->setFlash(__('The Film could not be saved. Please, try again.', true));
  55.             }
  56.         }
  57.     }
  58. }
  59.     function edit($id = null) {
  60.         if (!$id && empty($this->data)) {
  61.             $this->Session->setFlash(__('Invalid Film', true));
  62.             $this->redirect(array('action'=>'index'));
  63.         }
  64.         if (!empty($this->data)) {
  65.             if ($this->Film->save($this->data)) {
  66.                 $this->Session->setFlash(__('The Film has been saved', true));
  67.                 $this->redirect(array('action'=>'index'));
  68.             } else {
  69.                 $this->Session->setFlash(__('The Film could not be saved. Please, try again.', true));
  70.             }
  71.         }
  72.         if (empty($this->data)) {
  73.             $this->data = $this->Film->read(null, $id);
  74.             if ($this->Auth->user('id') = $this->data['Film']['user_id']) {
  75.                 $this->data = $this->Film->read(null, $id);
  76.             } else {
  77.                 $this->Session->setFlash('You are not Authorized to edit this film');
  78.             }
  79.         }
  80.     }
  81.  
  82.     function delete($id = null) {
  83.         if (!$id) {
  84.             $this->Session->setFlash(__('Invalid id for Film', true));
  85.             $this->redirect(array('action'=>'index'));
  86.         }
  87.         if ($this->Film->del($id)) {
  88.             $this->Session->setFlash(__('Film deleted', true));
  89.             $this->redirect(array('action'=>'index'));
  90.         }
  91.     }
  92.  
  93. }
  94. ?>
Parsed in 0.174 seconds, using GeSHi 1.0.7.14

Modify this Paste