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
Post a Comment