【发布时间】:2014-09-05 10:30:14
【问题描述】:
我使用 codeigniter 生成一些 html 选项,但我只得到一个结果,第一个结果来自表。
这是我的控制器
public function edit_event($id = 0){
$id = $this->uri->segment(3);
$current_id = $this->ion_auth->get_user_id();
$data['data'] = $this->as->the_event_edit($id);
$data['groups'] = $this->as->the_groups_list($current_id);
$this->load->view('editevent',$data);
}
这是我的模特
public function the_groups_list($current_id){
$query = $this->db->get_where('all_groups', array('group_owner' => $current_id));
foreach ($query->result() as $row)
{
$data = array(
'group_title' => $row->group_title,
'group_name' => $row->group_name,
'group_owner' => $row->group_owner
);
return $data;
}
}
这是另一个模型
public function as_event_edit($id){
$query = $this->db->get_where('all_scheduled_messages', array('id' => $id));
foreach ($query->result() as $row)
{
$data = array(
'as_title' => $row->as_title,
'as_event_name' => $row->as_event_name,
'as_owner' => $row->as_owner,
'as_type' => $row->as_type,
'as_target_dataset' => $row->as_target_dataset,
'as_timestamp' => $row->as_timestamp,
'as_time' => $row->as_time,
'as_day' => $row->as_day
);
return $data;
}
}
然后我在视图中使用$groups['group_title'],即使我有来自其他行的 4 个组标题,也只会显示第一个组标题。
我如何返回并传递一个数组,然后我可以将其传递给视图,以便使用 foreach 迭代和显示组标题?
【问题讨论】:
-
使用
$data[] = array(....而不是$data = array( -
我应该如何在视图中访问它?
标签: php codeigniter