我在显示数据从db到下拉列表时遇到了困难。
这就是我的尝试:
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>
它给我一个错误,说我的视图文件中有一个身份不明的变量员工。我已经看到了与此相关的问题,但到目前为止,他们所有的解决方案都不适用于我。
答案 0 :(得分:6)
加载视图时,您必须发送如下数据:
$this->load->view('evaluate_view', $data);