使用codeigniter激活停用状态

时间:2019-10-18 11:38:19

标签: codeigniter

我想从管理员端激活和停用类别; ff用户处于活动状态,然后在正面显示该类别。如何激活和停用类别?

使用Codeigniter,我想从管理员端激活和停用类别;如果用户处于活动状态,则在正面显示该类别。

如何激活和停用类别?我希望有一个按钮可以从管理员端点击活动和停用类别。

Controller:

         function update_status(){

              if(isset($_REQUEST['svalue']))
              {
                 $this->load->model('categorymodel','category');    
                 $set_status=$this->category->update_status();
                 if($set_status>0){
                    $this->session->set_flashdata('message',"category has been updated.");
                 }else{
                    $this->session->set_flashdata('message',"category has not been updated.");
                 }

              }
              return redirect("admin/category");
           }

Model:

          function update_status(){
              $sid=$_REQUEST['sid'];
              $svalue=$_REQUEST['svalue'];

              if($svalue=='active'){
                  $status='inactive';
              }else{
                  $status='active';
              }
              $data= array(
                                'status' => $status
                          );
             $this->db->where('id',$sid);
             return $this->db->update('category',$data);                
             }

View:        
          <td>
                          <?php
    $status = $data->status;
    if ($status == 'active') {
    ?>
                         <a href="<?php
        echo base_url();
    ?>admin/category/update_status?sid=<?php
        echo $data->id;
    ?>svalue=<?php
        echo $data->status;
    ?>" class="btn btn-success">Active</a>
                           <?php
    } else {
    ?>
                           <a href="<?php
        echo base_url();
    ?>admin/category/update_status?sid=<?php
        echo $data->id;
    ?>svalue=<?php
        echo $data->status;
    ?>" class="btn btn-danger">Inactive</a>
                            <?php
    }
    ?>

Table : 
Id Primary  int(11)     
category_name   varchar(255)        
slug    varchar(255)    
category_image  text    
created_at  timestamp       
updated_at  datetime        
status  enum('inactive', 'active')

1 个答案:

答案 0 :(得分:0)

当前,您在View中有以下代码。

<td> 
    <?php $status = $data->status; 
    if ($status == 'active') {?> 
        <a href="<?php echo base_url();?>admin/category/update_status?sid=<?php echo $data->id;?>?svalue=<?php echo $data->status;?>" class="btn btn success">Active</a> 
    <?php } else {?> 
        <a href="<?php echo base_url();?>admin/category/update_status?svalue=<?php echo $data->status;?>" class="btn btn-danger">Inactive</a> 
    <?php } ?> 
<td>

您应该进行以下更改

<td> 
    <?php $status = $data->status; 
    if ($status == 'active') {?> 
        <a title="Click to Deactivate" href="<?php echo base_url();?>admin/category/update_status?sid=<?php echo $data->id;?>&svalue=inactive" class="btn btn success">Active</a> 
    <?php } else {?> 
        <a title="Click to Activate" href="<?php echo base_url();?>admin/category/update_status?sid=<?php echo $data->id;?>&svalue=active" class="btn btn-danger">Inactive</a> 
    <?php } ?> 
<td>