我正在尝试使用数据库表中的一系列事件填充下拉表单。
我遇到各种各样的错误:
undefined $ user_events
等
我知道这是我从控制器传递数组的方式。
型号:
public function dropdown_add_event($id, $Id)
{
$sql = "SELECT *
FROM table_eventcards
WHERE table_eventcards.id = ?
AND table_eventcards.Id = ?";
$query = $this->db->query($sql, array($id, $Id));
return $query->result_array();
}
控制器:
$this->data['user_events'] = $this->model_location->dropdown_add_event(); // Retrieve an array of user events
查看:
<?php
$user_events = '';
if($user_events){
foreach($user_events as $events): {
?>
<div class="row">
<div class="col-md-12">
<h3>Add Event To Location</h3>
<div class="row">
<div class="row">
<div class="row">
<div id="myselect" class="col-md-12">
<p></p>
<div class="form-group col-xs-5 col-lg-3">
<?php
$attributes = 'input type="hidden" name="myselect" value="events[]"';
echo form_dropdown('myselect', $events, '',$attributes);
?>
<button id="grab1" type="button" class="btn btn-default">Clear</button>
<hr/>
</div>
</div>
</div>
</div>
</div>
<?php
}
endforeach;
}
?>
更新:
$ Id已定义为以上几行:
$data['Id'] = $this->session->userdata['logged_data']['member_id'];
答案 0 :(得分:1)
在您的控制器中,您似乎忘了给出参数:
$this->data['user_events'] = $this->model_location->dropdown_add_event();
// ^^ $id, $fkUserId
没有传递/找到参数dropdown_add_event();
只需传递控制器上的相应变量:
$fkUserId = $data['fkUserId'];
$this->data['user_events'] = $this->model_location->dropdown_add_event($id, $fkUserId);
$this->load->view('view_name', $this->data);