View:
<?php echo $this->UiForm->input('coverage.id', array('type' => 'hidden')); ?>
As you can see in my view I have created a hidden input field for my ID.
Controller:
public function processSpreadsheet($coverageId = null) {
if(!empty($this->data)) {
if(isset($this->data['Coverage']) && !empty($this->data['Coverage'])) {
if(array_key_exists('Spreadsheet', $this->data['Coverage']) && $this->data['Coverage']['Spreadsheet']['size'] > 0) {
$uploadedFile = $this->data['Coverage']['Spreadsheet'];
$coverageId = $this->Coverage->id;
$this->set('coverage.id', $coverageId);
$spreadsheetId = $this->Coverage->saveSpreadsheet($uploadedFile);
if($spreadsheetId) {
$this->Session->setFlash(__('Spreadsheet processed and saved successfully.', true));
$this->redirect(array(
'action' => 'edit',
$spreadsheetId
));
} else {
$this->Session->setFlash(__('Spreadsheet processing failed.', true));
$this->redirect(array(
'action' => 'add'
));
}
}
}
}
}
I have created a var called CoverageId in the controller also I have set the CoverageId as well.
Model:
public function saveSpreadsheet($uploadedFile) {
if(!empty($uploadedFile) && !empty($uploadedFile['tmp_name'])) {
if($uploadedFile['error'] == UPLOAD_ERR_OK) {
$pulledData = $this->extract($uploadedFile['tmp_name']);
$filePath = WWW_ROOT.'/spreadsheet/' . DS . $uploadedFile['name'] ;
if(!empty($pulledData)){
$pulledData = $this->Declination->ContactType->setSpreadsheetContactTypeIds($pulledData);
if(!empty($pulledData[$this->alias])) {
$this->save($pulledData[$this->alias]);
unset($pulledData[$this->alias]);
$coverageId = $this->id;
$pulledData = $this->setSpreadsheetCoverageIds($pulledData, $coverageId);
$pulledData = $this->CoverageInsured->setSpreadsheetCoverageInsuredIds($pulledData);
//$pulledData = $this->Policy->Location->setupSpreadsheetPolicyLocation($pulledData, $coverageId);
}
$this->CoverageInsured->save($pulledData['CoverageInsured']);
$this->Declination->saveAll($pulledData['Declination']);
$this->savePolicyData($pulledData);
$this->Spreadsheet->save($this->data);
move_uploaded_file($uploadedFile['tmp_name'], $filePath);
//$this->Policy->Location->saveAll($pulledData['Location']);
//$this->Policy->Company->saveAll($pulledData['Policy']);
return $coverageId;
}
}
}
return false;
}
Last but not least I am saving data to my spreadsheet table.
Im not sure what Im doing wrong or what I am not doing at all. If someone would please explain to me how this is suppose to work. I have read the documentation but some things are still unclear to me. I think I am doing something wrong in my controller and my model. As far as my model goes I think its just a matter of passing the right argument to the save method, and Im not sure what Im doing wrong in my controller. With that said, any input on this issue will be greatly appreciated!! Thanks!!
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment