将数据数组发送给函数而不使用serialize


Send an array of data to a function without using serialize

我有一个从excel中加载数据的数组,现在我需要将该数据发送到另一个视图以检查测试,但这没有发现,因为是函数中的数组,我尝试使用序列化和反序列化,但这会在url中发送字符限制的错误。

public function excel() {
    $this->loadModel('SoyaProductorCompra');
    $excel=array();
    $k=0;
    if ($this->request->is('post')) {
        $datos = new Spreadsheet_Excel_Reader();
        $datos->read($this->request->data['SoyaProductorCompra']['excel']['tmp_name']);
        for ($i = 2; $i <= $datos->sheets[0]['numRows']; $i++) {
            $excel[$k]['producto']=$datos->sheets[0]['cells'][$i][1];
            $excel[$k]['toneladas']=$datos->sheets[0]['cells'][$i][2];
            $excel[$k]['precio']=$datos->sheets[0]['cells'][$i][3];
            $excel[$k]['total']=$datos->sheets[0]['cells'][$i][4];
            $excel[$k]['fecha']=$datos->sheets[0]['cells'][$i][5];
            $excel[$k]['id']=$datos->sheets[0]['cells'][$i][6];
            $k++;
        }
        $this->set('excels',$excel);
        //return $this->redirect(array('action' => 'revision', serialize($excel))); not found
    }
}

这是我的另一个函数,它接收数组并显示在我的视图中,但没有找到

public function revicionexcel($data) {
    //$data=unserialize($data);  not work
    //debug($data); not work
}

无论如何我都不会通过查询字符串发送整个电子表格的数据,即使它足够小也不会这样做。我的意思是,如果有人开始手动编辑URL会发生什么?要么将数据写入文件,要么将其保存在会话中。

似乎你在同一个控制器内调用函数,对吗?

如果是,为什么不使用:

public function excel()
{
    //read excel into $excel variable
    $this->revicionexcel($excel);
}

所以这里不需要重定向

虽然建议您在model layer中读取excel,因为这一层用于所有类型的数据管理。

编辑:

然后,根据您的注释,您可以将所有读取移动到模型,并从控制器调用它:

SoyaProductorCompra 模型:

public function excel($data) {
    //your excel reading function as you have it on the controller.
    //change all "$this->request->data" references for the parameter "$data"
    //be sure to return the excel properly.
    ...
    return $excel;
}

SoyaProductorCompras 控制器:

public function revision()
{
    $excel = $this->SoyaProductorCompra->excel($this->request->data);
    $this->set('excels', $excel);
}

我们在这里做的是从动作revision()调用模型中的excel打开,并将它们发送到它的视图。这里不需要重定向