I have a CakePHP application that stores "mission" data. Every time a new mission is created, a static input file is read and 592 new records are inserted into the 'missions' table. Basically, a single column is populated with permanent data. I've got that working just fine. The Model code looks like this:
public function importCSV($csv_name) {
$sql = "LOAD DATA INFILE '{$csv_name}' INTO TABLE missions
LINES TERMINATED BY '\r'
(or_identity)";
$this->query($sql);
}
And here is the controller code:
public function add() {
if($this->request->is('post')) {
$this->Requirement->create();
$csv_name = /path/to/csv/file
if($this->Requirement->save($this->request->data)) {
$this->Requirement->importCSV($csv_name);
$this->Session->setFlash(__('The new mission has been created.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->SetFlash(__('Unable to create mission.'));
}
}
}
...and user input from the View:
echo $this->Form->input('mission_id', array('type' => 'textbox', 'label' => 'Mission ID (Ex: OA-5)'));
When a user creates a new mission, they are required to enter a Mission ID, which will be something like "OA-5." This Mission ID is in its own column in the 'missions' table. What I can't figure out how to do is make sure that Mission ID is inserted along with the 592 new records. It needs to be there to form a concatenated key. How can I modify my methods to allow this?