//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 :(得分:2)
您需要将$data
数组传递给控制器
$data['categories'] = $this->registrant_model->getAllDepartment();
$this->load->view('SystemAdminUser/registrant', $data);// pass $data to view