php - How to pass Codeigniter controller array to view and use foreach function? -


i can't access codeigniter controller array values in view. did miss.

mymodel

function get_data(){             $this->db->select('prod_id, content, details');     $query = $this->db->get('tblesample');             return $query->result();    } 

controller

public function index(){     $this->load->model('mymodel');      $user_info = $this->mymodel->get_data();      $this->load->view('inc/header_view');     $this->load->view('data_view', $user_info);         } 

data_view

<div class="col-md-9">     <?php         foreach ($user_info $info) {             echo $info->content;         }      ?>  </div> 

you better off using associative array pass on view:

public function index(){     $this->load->model('mymodel');      $data = [         'user_info' => $this->mymodel->get_data(),     ];      $this->load->view('inc/header_view');     $this->load->view('data_view', $data);         } 

and reference $user_info in view.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -