I am having some trouble saving an uploaded file to a table in MySQL database.
With that said, I have 2 fields in this table that references 2 other tables. One being user_id (which lets you know which user uploaded the file) , and the coverage_id(which let s you know which coverage the uploaded file belongs too).
I have tried adding this to my model with no luck.... $this->Spreadsheet->saveAl
Also I have added this to my model as well.....
public $hasOne = array(
'Spreadsheet' => array(
'className' => 'Spreadsheet',
'foreignKey' => 'coverage_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
);
Also I created a model called Spreadsheet and it is as follows....
public $name = 'Spreadsheet';
public $hasone = 'Coverage';
public $belongsTo = array(
'Coverage' => array(
'className' => 'Coverage',
'foreignKey' => 'coverage_id'
),
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
)
);
};
MySQL database table is as follows
id(varchar)
filename(varchar)
file(mediumblob)
user_id(varchar)
coverage_id(varchar)
created(datetime)
modified(datetime)
This is my model I use to process and save data from the uploaded file:
public function saveSpreadsheet($uploadedF
if(!empty($uploadedFile) && !empty($uploadedFile['tmp_
if($uploadedFile['error'] == UPLOAD_ERR_OK) {
$pulledData = $this->extract($uploadedFi
if(!empty($pulledData)){
$pulledData = $this->Declination->Contac
if(!empty($pulledData[$thi
$this->save($pulledData[$t
unset($pulledData[$this->a
$coverageId = $this->id;
$pulledData = $this->setSpreadsheetCover
$pulledData = $this->CoverageInsured->se
//$pulledData = $this->Policy->Location->s
}
$this->CoverageInsured->sa
$this->Declination->saveAl
$this->savePolicyData($pul
$this->Spreadsheet->saveAl
//$this->Policy->Location-
//$this->Policy->Company->
return $coverageId;
}
}
}
exit();
return false;
}
Here is my current controller:
public function processSpreadsheet() {
if(!empty($this->data)) {
if(isset($this->data['Cove
if(array_key_exists('Sprea
$uploadedFile = $this->data['Coverage']['S
$spreadsheetId = $this->Coverage->saveSprea
if($spreadsheetId) {
$this->Session->setFlash(_
$this->redirect(array(
'action' => 'edit',
$spreadsheetId
));
} else {
$this->Session->setFlash(_
$this->redirect(array(
'action' => 'add'
));
}
}
}
}
}
Finally here is my view:
<?php echo $this->UiForm->create(null
'type' => 'file',
'action' => 'processSpreadsheet',
'enctype' => 'multipart/form-data',
)); ?>
<?php echo $this->UiForm->input('Spre
'label' => '',
'rel'=>'tooltip',
'title' => 'Choose a completed SLIC Policy Template from your local system to import.',
'data-trigger'=>'hover',
'type' => 'file',
)); ?>
<?php echo $this->UiForm->end(array('
--
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 post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
No comments:
Post a Comment