我有這個$ data數組:(建在一個外殼,而不是一種形式)
(這裏調試)
array(
(int) 0 => array(
(int) 0 => 's511013t',
(int) 1 => 'id3422',
(int) 2 => '1'
),
(int) 1 => array(
(int) 0 => 's511013t',
(int) 1 => 'id3637',
(int) 2 => '1'
)
)
而且使用saveMany:
$this->Dir->saveMany($data, array('validate' => 'false', 'fieldList' => array('name','dir_dataname', 'project_id')));
保存失敗,沒有錯誤。
我不知道我的$ data數組是否格式良好,(我很困惑它是否應該有另一個級別)我從sql選擇等構建它。但它確實包含我需要保存的所有信息,單模型。
我從shell中運行了這一切,它的工作保存單個記錄每次提供的字段名稱:
// this works
$this->Dir->save(array('name' => $data[0][0], 'project_id' => $data[0][2], 'dir_dataname' => $data[0][1]));
已經閱讀保存數據,我很想用saveMany和由於我的自定義$數據格式的fieldList。 (我不想在我的$數據中插入字段名稱)。
(沒有sql_dump顯示,因爲從shell任務中獲取它非常麻煩)
我花了整整一個晚上試圖弄清楚,你能指出我在正確的方向嗎?
謝謝你們;我要做的是迭代我的索引數組並構建關聯結構;會回來。 <?PHP的 //關聯數組例如 $喜愛=陣列( 'OS'=> '窗口', '論壇'=> '的phpBB', '人'=>'周杰倫 ); ?> –
可疑的是,我使用了一個糟糕的$數據結構。 goggled如何將我的索引數組轉換爲關聯,然後保存:'foreach($ dataIndexed as $ num_linea => $ line_of_text){ $ data [$ num_linea] ['name'] = $ dataIndexed [$ num_linea] [1] ; $ data [$ num_linea] ['dir_dataname'] = $ dataIndexed [$ num_linea] [0]; $ data [$ num_linea] ['qca_interv'] = $ dataIndexed [$ num_linea] [2];' } 感謝您的指導。 ! –
我按照以下方式循環使用索引數組。你有什麼建議可以改進它嗎? 'foreach($ dataIndexed as $ num_linea => $ line_of_text){data_indexed [$ num_linea] [1]; $ data [$ num_linea] ['name'] = $ dataIndexed [$ num_linea] [1]; $ data [$ num_linea] ['dir_dataname'] = $ dataIndexed [$ num_linea] [0]; $ data [$ num_linea] ['qca_interv'] = $ dataIndexed [$ num_linea] [2]; }' –