-1

我想将一个数组和两个变量传递给我的视图我的数组已成功传递给视图,但是这两个变量是未定义的。谁能帮助我如何将这些值传递给视图。我尝试了索引,然后模型不起作用。

我的控制器

$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 之外,一切都很好。谢谢我提前

4

3 回答 3

1

在您的控制器中使用$data['semister'] = $Semister$data['dept'] = $Dept

于 2013-04-13T08:32:01.563 回答
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);

您可以像现在访问一样直接访问视图中的所有变量。

于 2013-04-13T08:32:32.497 回答
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);
于 2013-04-13T08:40:45.520 回答