我想将一个数组和两个变量传递给我的视图我的数组在视图中成功传递但是两个变量是undefined.can任何人都帮我如何将这些值传递给view.i尝试索引,然后模型没有'工作。
我的控制器
$Semister=$this->input->post('Semister');
$Dept=$this->input->post('Dept');
$this->load->model('Upload_Result_Model');
$data['subjects']=$this->Upload_Result_Model->getAllSubjects($Semister,$Dept);
$data['student']=$this->Upload_Result_Model->getAllStudent($Semister,$Dept);
$this->load->view('Faculty/upload_mid_result',$data,$Dept,$Semister);
我的观点
<h3>Department: <?php echo $Dept;?></h3> //error Undefined variable: Dept
<h3>Semister: <?php echo $Semister;?></h3> ////error Undefined variable: Dept
可以帮助我解决这个问题。除了$ dept和$ Semister之外,一切正常。 谢谢我提前
答案 0 :(得分:1)
在您的控制器中使用$data['semister'] = $Semister
和$data['dept'] = $Dept
答案 1 :(得分:1)
试试这个,
$data['Semister'] =$this->input->post('Semister');
$data['Dept'] =$this->input->post('Dept');
$this->load->model('Upload_Result_Model');
$data['subjects']=$this->Upload_Result_Model->getAllSubjects($data['Semister'],$data['Dept']);
$data['student']=$this->Upload_Result_Model->getAllStudent($data['Semister'],$data['Dept']);
$this->load->view('Faculty/upload_mid_result',$data);
您可以直接在视图中访问所有变量,就像您现在访问的那样。
答案 2 :(得分:0)
将数据发送到视图很容易
$this->load->model('Upload_Result_Model');
$semister = $this->input->post('Semister');
$Dept = $this->input->post('Dept');
$data['semister'] = $semister;
$data['dept'] = $Dept;
$data['subjects'] = $this->Upload_Result_Model->getAllSubjects($Semister,$Dept);
$data['student'] = $this->Upload_Result_Model->getAllStudent($Semister,$Dept);
$this->load->view('Faculty/upload_mid_result',$data);
$data
数组在视图方法中应用了php extract,你可以在这样的视图中使用数组的索引
echo $semister;
echo '<br>';
echo $dept;
echo '<br>';
echo '<pre>';
print_r($subjects);
echo '<pre>';
print_r($student);