So I have the object $this->data['VideoForm']['filename'] in the controller, but I want to append the return value of getExtension($filename) to it before I save it to the database. This is what I was trying:
$this->data['VideoForm']['filename'] = $this->data['VideoForm']['filename'] . "." . getExtension($this->data['VideoForm']['file']['name']);
It throws an error when I try to assign it a new value with the "=" or "=>" operator. Any idea of how to do it? I'm sure it's something very simple that I'm missing...
EDIT: This is the error:
Notice (8): Indirect modification of overloaded property MediaController::$data has no effect [APP/Controller/MediaController.php, line 31]
EDIT: I've continued looking around, and the getExtension() function is definitely returning "jpg" if I upload xxx.jpg, so that's not the problem. Any ideas?
That error is due to PHP 5.2+ change in the way __get() works -- it doesn't return a reference to the value, instead a read-only version. Cake 2.0+ uses __get() for some controller properties.
The solution in this case is to write to $this->request->data instead of $this->data.
Ref: Mark Story's post on Google groups
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With