我的一个项目有问题。我已经读完了,不知道该怎么做了。这是我们小型办公室的Codeigniter待办事项清单项目。我已经显示了数据库部分的内容,但是我对更新部分感到困惑。在视图部分,有一个带复选框的待办事项列表。如果他们完成了任务,那么他们会检查框,然后输入他们完成任务的日期和首字母。因此,他们可以检查很多任务并输入日期和首字母,并且我在一次更新它们时遇到问题。我很难过。请帮忙。谢谢!
控制器
public function update_tasks() {
$this->load->model('model_members');
$post=$this->input->post();
$this->model_memberdashboard->reset_tasks($this->session->userdata('UserID')); // resets completion status of all tasks since checkboxes that are not checked doesn't do Post
foreach ($post['checkbox'] as $row){
$newData = array(
'completed'=> 1
);
$this->model_members->update_tasks($newData,$row);
}
$this->index();
模型
public function update_tasks($data,$id) {
$this->db->update("mastertaskslist",$data,['id' => $id]);
}
查看< - 我使用bootstrap所以它有点长
foreach ($allowedTasklist_1 as $row) {
echo '<li class="ui-state-default clearfix">';
echo '<div class=row>';
echo '<div class="col-sm-1">';
$checkbox=array(
'name' => 'checkbox[]',
'id' => 'checkbox[]',
'type' => 'checkbox',
'value' => $row->id,
'checked' => $row->completed,
);
if ($row->completed=="False"){
unset($checkbox['checked']);
}
echo form_checkbox($checkbox);
echo '</div>';
echo '<div class="col-sm-1">';
echo '<label>'.$num.'.'.'</label>';
echo '</div>';
echo '<div class="col-sm-10">';
echo '<div class="row">';
echo '<div class="col-sm-12">';
echo '<p>'.$row->taskTitle.'</p>';
echo '</div>';
echo '</div>';
echo '<div class="row">';
echo '<div class="col-sm-8">';
if ($row->lastUpdate=='0000-00-00'){
$currDate=NULL;
} else {
$currDate=date('m/d/Y', strtotime($row->lastUpdate));
}
$date=array(
'type' => 'text',
'class' => 'datepicker',
'name' => 'date['.$row->id.']',
'id' => 'date['.$row->id.']',
'value' => $currDate,
'placeholder' => 'mm/dd/yyyy',
'size' => '15'
);
echo form_input($date);
echo '</div>';
echo '<div class="col-sm-4">';
$initials=array(
'name' => 'initials['.$row->id.']',
'id' => 'initials[]',
'value' => $row->initials,
'maxlength' => '100',
'size' => '3',
);
echo form_input($initials);
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
$num++;
echo '</li>';
}