我目前正試圖將各種記錄保存到同一模型中。CakePHP不保存數據到數據庫
我已閱讀有關數據格式的文檔,並且我的自定義數據數組符合此要求。
這是我的函數:
$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']);
他們都沒有工作。請幫忙,我做錯了什麼?
DarkRanger我編輯我的答案。 – Perefexexos