我有model
个数据传递给view
我这样成功地做到了这一点:
$var1 = $this->model_name->function_name();
$var2 = $this->model_name->function_name();
$var3 = $this->model_name->function_name();
$data = $var1 + $var2 + $var3;
$this->load->view('page_name', $data);
现在我正在其他方面使用上述方法,这种方法完美无瑕。但是我收到错误致命错误:不支持的操作数类型发生了什么?为什么它在一小时前工作并突然破坏而没有修改代码..
答案 0 :(得分:4)
您应该将多个变量放入数组中,如下所示:
$var1 = $this->model_name->function_name();
$var2 = $this->model_name->function_name();
$var3 = $this->model_name->function_name();
$data = array(
'var1' => $var1,
'var2' => $var2,
'var3' => $var3,
);
$this->load->view('page_name', $data);
或者Rick建议你可以使用它:
$data = array();
$data['var1'] = $this->model_name->function_name();
$data['var2'] = $this->model_name->function_name();
$data['var3'] = $this->model_name->function_name();
$this->load->view('page_name', $data);
有关阵列的更多信息:PHP Array