2013-04-13 69 views
-1

我想傳遞一個數組和兩個變量到我的視圖我的數組傳遞成功,但兩個變量是undefined。任何人都可以幫助我如何傳遞這些值來查看。我嘗試索引,然後模型不起作用。如何傳遞數組和變量在codigniter中查看

我控制器

$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 

可以ayone幫我解決這個problem.everything作品除了$部門和$ Semister罰款。 感謝我提前

回答

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

您可以訪問所有的變量直接針對像你現在是如何訪問。

+0

我試過,但在這種情況下,我從model.it中得到一個錯誤,說它是一個數組,它不能執行where函數。 –

+0

@RahatIslamKhan我更新了我的答案。看到了。 –

1

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

+0

我嘗試,則該模型獲得了」 t工作 –

+0

我的意思是在調用View之前調用Model函數。 –

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提取物在視圖的方法,你可以在視圖中使用陣列的索引這樣

echo $semister; 
echo '<br>'; 
echo $dept; 
echo '<br>'; 

echo '<pre>'; 
print_r($subjects); 
echo '<pre>'; 
print_r($student); 
相關問題