一切都很好,但它说严重性:通知消息:未定义的变量:类别

时间:2016-07-04 12:50:26

标签: php mysql codeigniter

//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提供的无效参数。请帮忙

1 个答案:

答案 0 :(得分:2)

您需要将$data数组传递给控制器​​

进行查看
$data['categories'] = $this->registrant_model->getAllDepartment();
$this->load->view('SystemAdminUser/registrant', $data);// pass $data to view