Maybe Cake does not like you calling a saveAll "inside" a saveAll?

A bit unrelated, but what is that afterSave doing? It looks like a lot
of work for little result. What I see is you finding all images in a
gallery ordered by the order_id. Then you set the order id of each one
to a number in increasing order and then saving them all again. That
is a lot of work just to make sure you don't have any gaps in the
numbering. Or I may be reading the code wrong. Google has an evil line
wrap as I'm sure you know.

I am guessing you allow the user to set the order of the edited image
in the form? Maybe you should look at an ordering solution that is
more suitable to the way the interface work? Or try to optimize the re-
ordering (you may want to give that job to MySQL).


/Martin


On Oct 1, 3:29 pm, WebbedIT <p...@webbedit.co.uk> wrote:
> I am having a problem with the below setup. All works well if editing
> a record without uploading new images, but if I upload an image the
> final line of my afterSave() function causes the saveAll() in my
> action to fail.  I know this as commenting out that line allows
> everything to work, but my numbering then goes out of sync without it.
>
> Any ideas why uploading an image through this form would stop that
> call running, the data that I am fetching and saving within the
> afterSave function is identical either way?!?
>
> form:
> echo $form->create('Image', array('type'=>'file', 'url'=>$html->url
> (array('action'=>'add'), true)));
>   echo $form->input('Image.id');
>   echo $form->input('Image.name');
>   echo $form->input('Image.gallery', array('options' => array
> ('portfolio'=>'portfolio', 'art-prints'=>'art-prints')));
>   echo $form->input('Image.full_image', array('type'=>'file'));
>   echo $form->input('Image.thumb_image', array('type'=>'file'));
>   echo $form->input('Image.html_title');
>   echo $form->input('Image.meta_description');
>   echo $form->input('Image.order_no');
> echo $form->end('Submit');
>
> action:
> if (!empty($this->data)) {
>   if ($this->data['Image']['full_image']['name']) $files[0] =
> 'full_image';
>   if ($this->data['Image']['thumb_image']['name']) $files[1] =
> 'thumb_image';
>   if (isset($files)) {
>     if ($data = $this->Uploader->uploadAll($files, true)) {
>       if ($this->data['Image']['full_image']['name']) $this->data
> ['FullImage'] = Set::merge($this->data['FullImage'], $data
> ['full_image']);
>       if ($this->data['Image']['thumb_image']['name']) $this->data
> ['ThumbImage'] = Set::merge($this->data['ThumbImage'], $data
> ['thumb_image']);
>       if ($this->Image->saveAll($this->data, array
> ('validate'=>'first'))) {
>         $this->Session->setFlash('<p>Image updated.</p>', 'default',
> null, 'admin');
>         $this->redirect(array('action'=>'index'));
>       } else {
>       echo '1';
>         $this->Session->setFlash('<p>Image not updated, correct errors
> and resubmit.</p>', 'default', array('class'=>'error'), 'admin');
>       }
>     } else {
>       $this->Session->setFlash('<p>Image not updated, correct errors
> and resubmit.</p>', 'default', array('class'=>'error'), 'admin');
>     }
>   } elseif ($this->Image->save($this->data)) {
>     $this->Session->setFlash('<p>Image updated.</p>', 'default', null,
> 'admin');
>     $this->redirect(array('action'=>'index'));
>   } else {
>     $this->Session->setFlash('<p>Image not updated, correct errors and
> resubmit.</p>', 'default', array('class'=>'error'), 'admin');
>   }} else {
>
>   $this->data = $this->Image->find('first', array('conditions'=>array
> ('Image.id'=>$id)));
>
> }
>
> afterSave:
> $result = $this->find('all', array(
>   'fields'=>array('Image.id', 'Image.order_no'),
>   'conditions'=>array('Image.gallery'=>$this->data['Image']
> ['gallery']),
>   'order'=>'order_no',
>   'contain'=>array()
> ));
> if ($result) {
>   foreach($result AS $k => $v):
>   $data['Image'][$k]['id'] = $v['Image']['id'];
>   $data['Image'][$k]['order_no'] = ($k + 1);
>   endforeach;}
>
> $this->saveAll($data['Image'], array('validate'=>false,
> 'callbacks'=>false));
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to