提问者:小点点

填充CodeIgniter MVC表时为Foreach()提供的参数无效


我是PHP/CodeIgniter新手,正在制作一个表,用于在特定时间段内从Mysql检索值的计数。

控制器类:

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()错误提供的无效参数:

基本上,我希望它是这样的,您只需传递开始日期和结束日期,它将返回一个表,其中包含每个status_to value count:


共1个答案

匿名用户

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

totalistings()-方法中,移动最后一行:

$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);
...