有没有办法使用 CodeIgniter 中的表单助手创建 MySQL 链接下拉菜单?我试图做到这一点,但我似乎无法让它发挥作用。
模型
function get_airports()
{
$this->db->select('airport_code, airport_name');
$this->db->order_by('airport_code', "asc");
$query = $this->db->get('airports');
foreach ($query->result_array() as $row){
$data{$row['airport_code']} = $row['status'];
}
}return $data;
}
function create_member()
{
$new_member_insert_data = array('first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'email_address'=> $this->input->post('email_address'),
'username'=> $this->input->post('username'),
'password'=> md5($this->input->post('password'))
'birthdate'=> $this->input->post('birthdate'),
'base'=> $this->input->post('base')
);
$insert = $this->db->insert('membership', $new_member_insert_data);
return $insert;
}
} ?>
看法
echo form_dropdown('base', set_value('base', 'Select a Base'));
控制器
$this->form_validation->set_rules('base', 'Base', 'trim|required');