如何获取数据从控制器到视图在编码器和打印视图


How to get data from Controller to view in codeigniter and print on view

如何在编码器中从控制器获取数据并打印视图中,我将数据发送给视图但在视图中,如果我执行print_r($data);,则没有显示

如何将数据放到视图上?

我如何在视图上显示我们打破数组,视图,控制器或模型的地方

控制器代码:

public function hopital_list($page = NULL)  {
    // getting hospital details
    $data = $this->hospitals_model->hospital_list();
    $this->load->view('catalog/view_hospitals_list', $data);           
}

模型代码:

public function hospital_list() {
    // getting hospital details
    $query = $this->db->get('wl_hospitals');
    return  $result = $query->result();    
}

我们没有将$data作为CodeIgniter中的变量传递。

我们实际上是将$data的键作为数组/变量在视图中传递。

所以,正确的代码应该是:
$data['hospitals'] = $this->hospitals_model->hospital_list();

打印:

echo '<pre>';
print_r($hospitals);
echo '</pre>';

试试这个:

 $data['hospitals_list'] = $this->hospitals_model->hospital_list();

   $this->load->view('catalog/view_hospitals_list', $data);

}

在视图中访问$hospitals_list。

视图:

foreach($hospitals_list as $row){
  //your code goes here
}

public function hospital_list() {
    $data = $query->result();
    if ($data) {
        $i = 0;
        foreach ($data as $dataP) {
            $menuName['view1'] = $dataP->view1;
            $menuName[$i]['view2'] = $dataP->view2;
            $menuName[$i]['view3'] = $dataP->view3;
            $menuName[$i]['view4'] = $dataP->view4;
            $i++;
        }
    }
    return $menuName;
}