Kurotsune
Kurotsune

Reputation: 27

Passing data from Controller to View with CodeIgniter

I'm having difficulty with display data from the db to dropdown.

This is what I have tried:

form_model.php

function getEmployee()
 {
    $this->db->select('username');
    $query = $this->db->get('tbl_usrs');

    return $query->result();
 } 

form_controller.php

public function evaluate()
{
    $data['employee'] = $this->form_model->getEmployee();
    $this->load->view('evaluate_view');
}

evaluate_view.php

<select class="form-control">
   <?php
       foreach($employee as $row)
       {
         echo '<option value="'.$row->username.'">'.$row->username.'</option>';
       }
   ?>
 </select>

It's giving me an error saying I have an unidentified variable employee in my view file. I've seen problems relating to this but so far all their solutions didn't work for me.

Upvotes: 1

Views: 77

Answers (1)

nestedl00p
nestedl00p

Reputation: 490

When you load the view you have to send the data like this:

$this->load->view('evaluate_view', $data);

Upvotes: 6

Related Questions