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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment