Confirming that $this->data is unset after save... in fact unset after the
AfterSave() callback.

Worked around it by setting the filename to a private property on first
generation of the filename....

any insight into why this unsetting goes on? I'm sure there is a good
reason......


On Thu, Feb 24, 2011 at 6:43 PM, Greg Skerman <gsker...@gmail.com> wrote:

> Hi,
>
> I've been working on a very simple app to upload and resize some images,
> and name the file in accordance with some information that has been provided
> in a form.
>
> To do this, my model has a public method "createFilename", which relies on
> $this->data to build the filename in accordance with the provided business
> rules.
>
> It was all working fine, until I connected the model to a database table
> and started also saving the meta-data.... now it appears $this->data is
> being unset for subsequent calls to the method.
>
> The method is simple enough:
>
> public function createFilename() {
>         CakeLog::write('debug', 'photo name is '. 
> $this->data['Photo']['name']);
>         $name = $this->data['Photo']['name'];
>         $level = $this->data['Photo']['level'];
>         $category = $this->data['Photo']['category'];
>         $month = strtoupper($this->data['Photo']['month']);
>
>         return $level . $category . $month . $name . '.jpg';
> }
>
> According to the information that I log, in the 4 times this method is
> called during the processing of the image, the first time $this->data[
> 'Photo']['name']  contains data, and then each subsequent call is empty.
>
> The first time the method is called is at validation to prevent duplicate
> files with the same metadata being created, and this seems to be working
> fine, but then the following times (which are used for naming the file after
> it has been manipulated, moving the file out of the TMP directory into the
> uploaded images directory, and including the filename in an email
> attachment, $this->data appears to be empty.
>
> Does the act of saving a record to the database automatically unset the
> $this->data variable or is there something else going on here?
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to