0
我使用Excel Reader將excel文件導入到我的數據庫中。我也使用postgres和cakephp。現在我有問題的信息導入到我的數據庫,我試圖通過一個輸入。錯誤的我需要在我的數據庫中輸入數據數組,數據從excel文件導入
消息:
Call to a member function create() on a non-object.
我的控制器。
<?php
App::import('Vendor', 'excel_reader2');
class SoyaproductorcomprasController extends AppController {
public $components = array('Session','RequestHandler');
public function logout() {
$this->redirect($this->Auth->logout());
}
public function excel() {
$this->loadModel('SoyaProductorCompra');
if ($this->request->is('post')) {
$datos = new Spreadsheet_Excel_Reader();
$datos->read($this->request->data['SoyaProductorCompra']['excel']['tmp_name']);
for ($i = 1; $i <= $datos->sheets[0]['numRows']; $i++) {
$this->SoyaProductorCompra->create();
$this->request->data['SoyaProductorCompra']['user_id'] = $this->Auth->user('id');
$this->request->data['SoyaProductorCompra']['campana'] = $datos->sheets[0]['cells'][$i][1];
$this->request->data['SoyaProductorCompra']['nit'] = $datos->sheets[0]['cells'][$i][2];
$this->request->data['SoyaProductorCompra']['proveedor'] = $datos->sheets[0]['cells'][$i][3];
$this->request->data['SoyaProductorCompra']['regimengrano'] = $datos->sheets[0]['cells'][$i][4];
$this->request->data['SoyaProductorCompra']['codigograno'] = $datos->sheets[0]['cells'][$i][5];
$this->request->data['SoyaProductorCompra']['producto'] = $datos->sheets[0]['cells'][$i][6];
$this->request->data['SoyaProductorCompra']['toneladas'] =$datos->sheets[0]['cells'][$i][7];
$this->request->data['SoyaProductorCompra']['preciodolar'] = $datos->sheets[0]['cells'][$i][8];
$this->request->data['SoyaProductorCompra']['total'] = $datos->sheets[0]['cells'][$i][9];
$this->request->data['SoyaProductorCompra']['fecharegistro'] = $datos->sheets[0]['cells'][$i][10];
$this->SoyaProductorCompra->save($this->data);
}
}
}
}
?>
我的看法。
<?php echo $this->Form->create('SoyaProductorCompra', array('enctype' => 'multipart/form-data'));?>
<?php
echo $this->Form->input('excel',array('type' => 'file', 'label'=>'Ingrese excel'));
echo $this->Form->end('Submit')
?>
'$這個 - > SoyaProductorCompra->保存($這個 - >數據)'!=='$這個 - > SoyaProductorCompra->保存($ this-> request-> data)' –
抱歉沒有找到,但是謝謝。 – CoolLife
那麼,問題是什麼? – Smandoli