2016-07-04 27 views
0
//controller: 
private function getAll() { 

    $data['categories'] = $this->registrant_model->getAllDepartment(); 
    $this->load->view('SystemAdminUser/registrant', $data); 

} 

//model: 
public function getAllDepartment() { 
    $this->db->select('*')->from('patient_db'); 
    $query = $this->db->get(); 
    return $query->result_array(); 

} 


//view: 
<?php foreach($categories as $c):?> 
    <tr> 
     <td><?php echo $c['id'];?></td> 
     <td><?php echo $c['phone'];?></td> 
     <td><?php echo $c['name'];?></td> 
    </tr> 
<?php endforeach;?> 

這是代碼。每次它說爲foreach提供的未定義變量和無效參數。請幫助一切正常,但它說嚴重性:通知消息:未定義的變量:類別

+0

,查看哪裏是定義的變量$類別?我認爲你的意思是:$ categories = $ this-> registrant_model-> getAllDepartment(); –

+2

我想你的意思是輸入'$ data ['categories']'而不是'$ categories' – Pete

+2

[PHP:「Notice:Undefined variable」和「Notice:Undefined index」](http:// stackoverflow。 com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – ShiraNai7

回答

2

你需要傳遞$data陣列控制器從

$data['categories'] = $this->registrant_model->getAllDepartment(); 
$this->load->view('SystemAdminUser/registrant', $data);// pass $data to view 
+0

同樣的問題。未解決 – oxy

+2

'print_r($ data)'在控制器中併發布其值 – Saty

相關問題