填充 CodeIgniter MVC 时为 foreach() 提供的参数无效 table

Invalid argument supplied for foreach() while filling CodeIgniter MVC table

我是 PHP/CodeIgniter 的新手,我正在制作一个 table 来检索特定时间范围内 Mysql 的值计数。

控制器Class:

public function totallistings($slug='')
    {
        $this->load->library('pagination');
        $main['page_title']=$this->config->item('site_name').' - Listings Reports';
        $main['header']=$this->adminheader();
        $main['footer']=$this->adminfooter();
        $main['left']=$this->adminleftmenu();  
        $content='';
        $fdate = $this->input->post("fdate");
        $content['tdate'] = $tdate = $this->input->post("tdate");
        if(isset($fdate)){
            $content['fdate'] =$fdate;
        }else{
            $content['fdate'] = '';
        }
        if(isset($tdate)){
            $content['tdate'] =$tdate;
        }else{
            $content['tdate'] ='';
        }
        $main['content']=$this->load->view('crm/reports/totallistings',$content,true);
        $main['jsArray'] = array('public/assets/plugins/datatables/jquery.dataTables.min.js' );  
        $main['cssArray'] = array('public/assets/plugins/datatables/jquery.dataTables.min.css','public/assets/css/reports.css');
        $this->load->view('crm/main',$main);
        $content['groupedleads'] = $this->leads_model->get_listingstatus($fdate,$tdate);
    }

但这在我的网页上给了我一个为 foreach() 提供的无效参数错误:

基本上我想把它变成这样,你只需传递开始日期和结束日期,它 returns 一个 table 每个 status_to 值计数:

您需要在加载视图之前将数据设置到数组中,否则视图中将不存在值groupedleads

在您的 totallistings() 方法中,移动最后一行:

$content['groupedleads'] = $this->leads_model->get_listingstatus($fdate,$tdate);

并在加载视图之前放置它:

$content['groupedleads'] = $this->leads_model->get_listingstatus($fdate,$tdate);
$main['content'] = $this->load->view('crm/reports/totallistings',$content,true);
...