Я прочитал документацию, касающуюся формата данных, и мой собственный массив данных соответствует этому .
Это моя функция:
Код: Выделить всё
$k = 0;
foreach($this->request->data['FileData'] as $data) {
$name = substr($data['name'],0,strpos($data['name'],'_'));
$ext = substr($data['name'],strrpos($data['name'],'.')+1);
$display_name = str_replace('.'.$ext,'',str_replace($name . '_','',$data['name']));
$Clinic = $this->Clinic->find('first',
array(
'conditions' => array(
'Clinic.name' => strtoupper($data['owner'])
),
'fields' => array('id')
)
);
$Data['Upload'][$k]['clinic_id'] = $Clinic['Clinic']['id'];
$Data['Upload'][$k]['file_name'] = $data['name'];
$Data['Upload'][$k]['display_name'] = $display_name;
$Data['Upload'][$k]['extension'] = $ext;
$k++;
}
$this->Upload->create();
if ($this->Upload->saveMany($Data,array('deep'=>true))) { ** READ BELOW
$this->Session->setFlash(__('The upload has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The upload could not be saved. Please, try again.'));
}
Код: Выделить всё
array(
'Upload' => array(
(int) 0 => array(
'clinic_id' => '72',
'file_name' => 'MAHLUNGULU CLINIC_0_Guide_Tax_Season_2012_Insert_Afrikaans.pdf (6).pdf',
'display_name' => '0_Guide_Tax_Season_2012_Insert_Afrikaans (6)',
'extension' => 'pdf'
),
(int) 1 => array(
'clinic_id' => '79',
'file_name' => 'ZAMA ZAMA CLINIC_1377256_515345465221385_1613340746_n.jpg',
'display_name' => '1377256_515345465221385_1613340746_n',
'extension' => 'jpg'
),
(int) 2 => array(
'clinic_id' => '72',
'file_name' => 'MAHLUNGULU CLINIC_07reader.xlsx',
'display_name' => '07reader',
'extension' => 'xlsx'
),
(int) 3 => array(
'clinic_id' => '79',
'file_name' => 'ZAMA ZAMA CLINIC_13-disturbed-i_still_havent_found_what_im_looking_for.mp3',
'display_name' => '13-disturbed-i_still_havent_found_what_im_looking_for',
'extension' => 'mp3'
)
)
)
** Я пробовал следующее методы сохранения, все они терпят неудачу:
Код: Выделить всё
$this->Upload->saveMany($Data,array('deep',true));
$this->Upload->saveMany($Data['Upload'],array('deep',true));
$this->Upload->save($Data);
$this->Upload->save($Data['Upload']);
$this->Upload->saveAll($Data);
$this->Upload->saveAll($Datap['Upload']);
Подробнее здесь: https://stackoverflow.com/questions/212 ... o-database
Мобильная версия