我想知道这两种形式中哪一种在 Codeigniter 中更有效。在选项 1 中,数据数组被传递给所有视图。在选项 2 中,每个数据数组都有不同的名称,以免忘记每个视图的所有信息。我想假设选项 2 是正确的,我的意思是重命名每个数组,而不是在每个视图上花费不必要的信息。我对么?Codeigniter 是否重要?感谢您阅读帖子问候
选项1
public function alguna_funcion(){
$data['datos1'] = $this->modelo->function1();
$data['widget1'] = $this->load->view('widget1',$data,TRUE);
$data['datos2'] = $this->modelo->function2();
$data['widget2'] = $this->load->view('widget2',$data,TRUE);
$data['datos3'] = $this->modelo->function3();
$data['widget3'] = $this->load->view('widget3',$data,TRUE);
$data['datos4'] = $this->modelo->function4();
$data['widget4'] = $this->load->view('widget4',$data,TRUE);
$this->load->view('home_view',$data);
}
选项 2
public function alguna_funcion(){
$data1['datos1'] = $this->modelo->function1();
$data['widget1'] = $this->load->view('widget1',$data1,TRUE);
$data2['datos2'] = $this->modelo->function2();
$data['widget2'] = $this->load->view('widget2',$data2,TRUE);
$data3['datos3'] = $this->modelo->function3();
$data['widget3'] = $this->load->view('widget3',$data3,TRUE);
$data4['datos4'] = $this->modelo->function4();
$data['widget4'] = $this->load->view('widget4',$data4,TRUE);
$this->load->view('home_view',$data);
}