我正在开发一个考勤管理codeigniter应用程序,我正在使用切换开关插件来更新出勤状态。这个过程将是:
这是我应用的预览。我需要使用AJAX这个表单。
这是我的观点代码:
<!-- student attendence status update form -->
<form method="post" action="<?php echo base_url(); ?>index.php?admin/student_attendance">
<!-- start datatable -->
<table class="table table-hover dataTable table-striped width-full" id="departmentTableTools">
<thead>
<tr>
<th class="text-center"><?php echo get_phrase('rool'); ?></th>
<th class="text-center"><?php echo get_phrase('name'); ?></th>
<th class="text-center"><?php echo get_phrase('status'); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach($students as $row):?>
<tr>
<td class="text-center"><?php echo $row['roll_no'];?></td>
<td class="text-center"><?php echo $row['name'];?></td>
<td class="text-center">
<input type="checkbox" value="1" name="status_<?php echo $row['student_id'];?>" data-plugin="switchery" <?php if($status == 1) echo 'checked'; ?>/>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<input type="hidden" name="date" value="<?php echo $full_date;?>" />
</form>
<!-- end the attendance status update form -->
&#13;
这是我的控制器代码:
if($_POST) // if the update request is send
{
foreach ($students as $row)
{
$this->crud_model->update_student_attendance($students['student_id'], $this->input->post('status_' . $row['student_id']), $this->input->post('date'));
}
$this->session->set_flashdata('flash_message' , get_phrase('data_updated'));
redirect(base_url() . 'index.php?admin/student_attendance/'.$date.'/'.$month.'/'.$year.'/'.$program_id.'/'.$batch_id , 'refresh');
}
&#13;
这是我更新的模型代码和db值:
function update_student_attendance($student_id, $attendance_status, $full_date){
$this->db->where('student_id' , $student_id);
$this->db->where('date' , $full_date);
$this->db->update('attendance' , array('status' => $attendance_status));
}
&#13;