0

我在单击复选框时接受和拒绝一些数据。从我的代码中接受代码运行良好,但拒绝是相同类型的代码,但运行不正常。

我的查看页面代码:

 <form  class="form-horizontal" method="POST" action="<?=site_url('Request/Update_Event')?>">
    <div class="panel panel-flat" id="id">
      <div  class="panel-heading">
       <center> <h4 class="panel-title">Request Portal</h4></center>

      </div> <button type="submit" class="btn btn-info btn-lg">
          <span class="glyphicon glyphicon-thumbs-up"></span>Approved
        </button> <a href="<?=site_url('Request/Rejected')?>" class="btn btn-info btn-lg" id="but">
          <span class="glyphicon glyphicon-thumbs-down"></span> Rejected
        </a><div>

我的控制器代码:

public function Update_Event(){
    $empid = $this->input->post('empid');
        for($i=0; $i< sizeof($empid); $i++)
    {

        $data = array(
            'backgroundColor' => 'green',
            'event_status' =>'Approved',
        );
        $this->db->where(empid,$empid[$i]);
        $this->db->update('events',$data);
}

redirect('Request','refresh');
}
public function Rejected(){
$empid = $this->input->post('empid');
        for($i=0; $i< sizeof($empid); $i++)
    {

        $data = array(
            'backgroundColor' => 'red',
            'event_status' =>'Rejected',
        );
        $this->db->where(empid,$empid[$i]);
        $this->db->update('events',$data);
}

redirect('Request','refresh');
print_r($empid);
}

我的表代码:

<table id="tb2" class="table datatable-responsive" >
    <thead><tr><h6><th></th><th  align="center">Name</th>
            <th class="col-sm" >Leave Date</th>
            <th class="col-sm" >Reason</th>
    </tr></thead>
            <?php foreach ($query as $row): ?>                          
    <tr><td><input type="checkbox" name="empid[]" value="<?php echo $row['empid'];?>"></td>
    <td>Leave Applied By <?php echo $row['first_name'];?> <?php echo $row['last_name'];?></td>
    <td><?php echo date('d/m/Y', strtotime($row['event_date']));?></td>
    <td><?php echo $row['title'];?> </td>

</tr></tbody><?php endforeach ?>
    </table>    

被拒绝的代码在我的代码中不起作用,并且当我打印 empid 值时,empid 没有传递给被拒绝的代码

4

1 回答 1

2

您正面临这个问题,因为在批准时您正在提交表单,而在拒绝时您只点击链接。因此,当您单击拒绝按钮时,它不会向控制器发布任何值。

你可以做这样的事情。只需将额外的参数传递给拒绝函数。

<a href="<?=site_url('Request/Rejected/123')?>" class="btn btn-info btn-lg" id="but">
          <span class="glyphicon glyphicon-thumbs-down"></span> Rejected
</a>


public function Rejected($empid = ''){
        for($i=0; $i< sizeof($empid); $i++)
    {

        $data = array(
            'backgroundColor' => 'red',
            'event_status' =>'Rejected',
        );
        $this->db->where(empid,$empid[$i]);
        $this->db->update('events',$data);
}

redirect('Request','refresh');
print_r($empid);
}
于 2020-03-06T07:32:47.400 回答