2

控制器

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

现在我在其他工作完美的领域使用上述方法。但是我收到一个错误致命错误:不支持的操作数类型发生了什么?为什么它在一小时前工作并突然中断而没有修改代码..

4

1 回答 1

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 数组

于 2012-10-11T22:56:29.677 回答