CakePHP 2.2.1のインストールで、CakeDCによるUtilsプラグインのcsvUpload動作を使用しています。
かなり大きなcsvを正常に処理しているので、うまく機能しています。ただし、私のテーブル/モデルには、一貫性のない関連モデルのIDに基づいているため、固定と見なされる2つのフィールドがあります。したがって、これらの固定値を変数を介して取得する必要があります。これは非常に簡単です。
だから私の質問は、csvUploadの固定フィールドの側面をどのように使用するのですか?私はそれを次のように試しましたが、明らかに機能しなかった多くの小さなバリエーションがあります。
public function upload_csv($Id = null) {
$unique_add = 69;
if ( $this->request->is('POST') ) {
$records_count = $this->Model->find( 'count' );
try {
$fixed = array('Model' => array('random_id' => $Id, 'unique_add' => $unique_add));
$this->Model->importCSV($this->request->data['Model']['CsvFile']['tmp_name'], $fixed);
} catch (Exception $e) {
$import_errors = $this->Model->getImportErrors();
$this->set( 'import_errors', $import_errors );
$this->Session->setFlash( __('Error Importing') . ' ' . $this->request->data['Model']['CsvFile']['name'] . ', ' . __('column name mismatch.') );
$this->redirect( array('action'=>'import') );
}
$new_records_count = $this->Model->find( 'count' ) - $records_count;
$this->Session->setFlash(__('Successfully imported') . ' ' . $new_records_count . ' records from ' . $this->request->data['Model']['CsvFile']['name'] );
$this->redirect(array('plugin'=>'usermgmt', 'controller'=>'users', 'action'=>'dashboard'));
}
}
私が検索したときにこの動作に関する投稿を1つしか見つけられなかったので、どんな助けでも大歓迎です...