[英]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 form_model.php
function getEmployee()
{
$this->db->select('username');
$query = $this->db->get('tbl_usrs');
return $query->result();
}
form_controller.php form_controller.php
public function evaluate()
{
$data['employee'] = $this->form_model->getEmployee();
$this->load->view('evaluate_view');
}
evaluate_view.php Evaluation_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.
我已经看到与此相关的问题,但到目前为止,所有解决方案都不适用于我。
加载视图时,您必须像这样发送数据:
$this->load->view('evaluate_view', $data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.