次の CSV ファイルがあります。最初の行はヘッダーです。
admission_no;first_name;last_name;gender;date_of_birth;join_date;form_id;stream_id;school_photo
1003;"cavin";"cavin";"cavin";"male";1992-11-02;2007-01-25;1;1
1004;"joshua";"joshua";"joshua";"male";1992-11-03;2007-01-26;1;1
1005;"elijah";"elijah";"elijah";"male";1992-11-04;2007-01-27;1;1
1006;"lawrent";"lawrent";"lawrent";"male";1992-11-05;2007-01-28;1;1
1007;"steven";"steven";"steven";"male";1992-11-06;2007-01-29;1;2
1008;"javan";"javan";"javan";"male";1992-11-07;2007-01-30;1;2
1009;"miller";"miller";"miller";"male";1992-11-08;2007-01-31;1;2
1010;"javis";"javis";"javis";"male";1992-11-09;2007-02-01;1;2
1011;"fredrick";"fredrick";"fredrick";"male";1992-11-10;2007-02-02;1;3
1012;"fredrick";"fredrick";"fredrick";"male";1992-11-11;2007-02-03;1;3
1013;"nahashon";"nahashon";"nahashon";"male";1992-11-12;2007-02-04;1;3
1014;"nelson";"nelson";"nelson";"male";1992-11-13;2007-02-05;1;3
1015;"martin";"martin";"martin";"male";1992-11-14;2007-02-06;1;4
1016;"felix";"felix";"fwlix";"male";1992-11-15;2007-02-07;1;4
1017;"tobias";"tobias";"tobias";"male";1992-11-16;2007-02-08;1;4
1018;"dennis";"dennis";"dennis";"male";1992-11-17;2007-02-09;1;4
1019;"bildad";"bildad";"bildad";"male";1992-11-18;2007-02-10;1;5
1020;"syslvester";"sylvester";"sylvester";"male";1992-11-19;2007-02-11;1;5
そしてadmission_no
、私のデータベース テーブルfirst_name
のlast_name
列gender
は、、、、、、、、、およびdate_of_birth
です。join_date
form_id
stream_id
school_photo
CakeDC Utils プラグインを使用してデータをインポートすると、次のようなフラッシュ メッセージが表示されます。
file.csv から 0 件のレコードが正常にインポートされました
ヘッダーを削除したり、区切り文字を変更したりNULL
、school_photo
列に追加したりしましたが、null 許容であるため、何も機能していないようです。
誰かが間違っていることを教えてもらえますか?
Ubuntu libre Office のインポート機能を使用して csv を生成しています。
function import() {
$modelClass = $this->modelClass;
if( $this->request->is('POST') ) {
$records_count = $this->$modelClass->find('count');
try {
$this->$modelClass->importCSV($this->request->data[$modelClass]['CsvFile']['tmp_name']);
}catch (Exception $e) {
$import_errors = $this->$modelClass->getImportErrors();
$this->set('import_errors', $import_errors);
$this->Session->setFlash(__('Error importing')." ".$this->request->data[$modelClass]['CsvFile']['name']. ",". __('column mismatch'));
$this->redirect(array('action' => 'import'));
}
$new_records_count = $this->$modelClass->find('count') - $records_count;
$this->Session->setFlash(__('Successfully imported')." ". $new_records_count . " ".'records from' . " ".$this->request->data[$modelClass]['CsvFile']['name']);
//$this->redirect(array('action' => 'index'));
}
$this->set('modelClass', $modelClass);
$this->render('../Common/import');
}// インポートを終了
ビューファイル
<h3>Import <?php echo Inflector::pluralize($modelClass); ?> from CSV data file</h3>
<?php
echo $this->Form->create($modelClass, array('action' => 'import', 'type' => 'file'));
echo $this->Form->input('CsvFile', array('label' => '', 'type' => 'file'));
echo $this->Form->end('Submit');
?>