我需要在我的数据库中输入数据数组,数据是从excel文件导入的


I need to enter an array of data in my database, the data is imported from a excel file

我使用Excel Reader导入Excel文件到我的数据库。我也使用postgres和cakephp。现在我有问题导入信息到我的数据库,我试图通过一个for.

错误信息:

在非对象上调用成员函数create()。

我的控制器。

<?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')
?>

不确定,试着在$this->SoyaProductorCompra->save($this->request->data);之前调用$this->SoyaProductorCompra->create();