Hello folks, Just writing a model Behavior and got stuck onto something....
Is there a way to save multiple records using the beforeSave method in the Behavior??? I got the following code, but for some reason it fails or the data is erased etc... foreach($files as $i => $file){ $dest = $file['destination']; if($this->uploadFile($file['tmp_name'],$this->setPath($model, $dest))){ $src = $this->setPath($model,$dest); $thumb->renderThumb(array('src'=>$src)); //$thumb->renderThumb(array('src'=> $src,'w'=>'600','h' => '600')); $model->data[$model->alias][$fileField] = $dest; $listed[] = $dest; if($this->__settings[$model->alias]['list'] == false){ $conditions_data = $model->data[$model->alias]; $fields = array_keys($conditions_data); if(isset($conditions_data['created'])) unset($conditions_data['created']); if(isset($conditions_data['modified'])) unset($conditions_data['modified']); $conditions = array(); //foreach($conditions_data as $key => $value) //$conditions[$model->alias. '.'. $key] = $value; //unset($conditions_data[$key]); $conditions[$model->alias. '.'. $fileField] = $dest; $params = array('conditions'=> $conditions); //if($model->find('count',$params)) unset($files[$i]); continue; //$model->create(); //pr($model->data); $result = $model->save($model->data,$validate = false,$fields); //$model->id; //$listFields = implode(',',$fields); //$querySql = "INSERT INTO {$model->useTable} ({$listFields}) VALUES ({$listValues});"; if(!$result){ //echo '<br />Failed saving to database, deleting file now...'; unlink($this->setPath($model,$dest)); } } } } Many thanks in advance for your help! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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