在PHP CodeIgniter中将数组作为参数传递给Model

By simon at 2018-02-28 • 0人收藏 • 46人看过

我试图在Code-Igniter中将Array as parameter传递给Stored Procedure 应用。当我打印该数组时,它给了我正确的答案选定的结果 值。但是它在模型函数中给了我一个错误。 这是我的控制器:

public function index()
{
        $propertyType=$this->input->post('property_type');
        $area=$this->input->post('area_id');
        $clustersID['cluster']=$this->input->post('cluster_id');
        $stageId=$this->input->post('property_status');
        print_r($clustersID);
        $data['properties'] = $this->p->getPropertyByAreaCluster($propertyType, $area, $clustersID, $stageId);

            // echo "<pre>";
            // print_r($data['properties']);
            // echo "
"; // exit(); //$data['props'] = $this->p->PropView($propId); $this->load->view('template/header', $data); $this->load->view('Property/property_view', $data); $this->load->view('template/footer'); } 这是我的M奥德尔:
public function getPropertyByAreaCluster($propertyType, $area, $clustersID, $stageId)
    {
        $query = $this->db->query("call fetch_propertyType_Area_Cluster_Stage($propertyType,$area,$clustersID,$stageId)");
        if ($query) {
            $data = $query->result();
            $query->next_result(); 
            $query->free_result();
            return $data;
        }else{
            return false;
        }
    }
错误:

遇到PHP错误严重性:通知

消息:数组到字符串的转换

Filename:models / Property_m.php

行号:26

Backtrace:

文件:/ opt / lampp / htdocs / livemg / application / models / Propertym.php线路:26 函数:error_handler

文件:/opt/lampp/htdocs/livemg/application/controllers/Property.php行:61 功能:getPropertyByAreaCluster

文件:/opt/lampp/htdocs/livemg/index.php行:315函数:require_once

数据库错误Occurred错误号码:1054

'字段列表'中的未知列'数组'

调用fetchpropertyTypeAreaClusterStage(0,0,数组,0)> 文件名:models / Property_m.php

行号:26

1 个回复 | 最后更新于 2018-02-28
2018-02-28   #1

我有一个答案,只是将该数组转换为字符串并传递它。

    public function index()
    {
        $propertyType=$this->input->post('property_type');
        $area=$this->input->post('area_id');
        $clustersID['cluster']=$this->input->post('cluster_id');
        $clusterString = implode(',', $clustersID['cluster']);

        echo "<pre>";
        // var_dump($clustersID['cluster']);
        echo $clusterString;
        echo "
"; $stageId=$this->input->post('property_status'); print_r($clustersID); $data['properties'] = $this->p->getPropertyByAreaCluster($propertyType, $area, $clustersID, $stageId); //$data['props'] = $this->p->PropView($propId); $this->load->view('template/header', $data); $this->load->view('Property/property_view', $data); $this->load->view('template/footer'); }

登录后方可回帖

Loading...