Я создаю кнопку «Активный / Неактивный статус» для своей страницы, но данные с контроллера не отправляются в Модель.
Это мой код.
Баннер контроллера . php
public function banner_list()
{
$data['title'] = "Banner Type List";
$session = $this->session->userdata('username');
if(empty($session)){
redirect('admin/');
}
$this->load->view("admin/banner/banner_list", $data);
// Datatables Variables
$draw = intval($this->input->get("draw"));
$start = intval($this->input->get("start"));
$length = intval($this->input->get("length"));
$bannertype = $this->Banner_model->get_bannertypes();
//echo json_encode($bannertype);
$data = array();
foreach($bannertype->result() as $r) {
$status = $r->status;
$btn = "";
if($status=="active") {
$btn = '<a href="<?php
echo base_url();
?>admin/banner/update_status?sid=<?php
echo $r->banner_id;
?>&svalue=inactive" class="btn btn-success">Active</a>' ;
} else {
$btn = ' <a href="<?php
echo base_url();
?>admin/banner/update_status?sid=<?php
echo $r->banner_id;
?>&svalue=active"
class="btn btn-danger">Inactive</a>' ;
}
$data[] = array(
$r->banner_url,
$r->banner_name,
$r->display_image,
$btn,
// '<button type="button" id="status_checks" class="status_checks btn-success" value="$r->status">"'.$r->status.'" </button>',
'<span data-toggle="tooltip" data-placement="top" title="Edit"><button type="button" class="btn btn-info btn-circle btn-xs" data-toggle="modal" data-target=".edit-modal-data" data-banner_id="'. $r->banner_id . '"><span class="fas fa-pencil-alt"></span></button></span><span data-toggle="tooltip" data-placement="top" title="Delete"><button type="button" class="btn btn-danger btn-circle btn-xs delete" data-toggle="modal" data-target=".delete-modal" data-record-id="'. $r->banner_id . '"><span class="fa fa-times"></span></button></span>',
);
}
$output = array(
"draw" => $draw,
"recordsTotal" => $bannertype->num_rows(),
"recordsFiltered" => $bannertype->num_rows(),
"data" => $data
);
echo json_encode($output);
exit();
}
Модель Banner_model. php
function update_status(){
$sid=$_REQUEST['banner_id'];
$svalue=$_REQUEST['svalue'];
if($svalue=='active'){
$status='inactive';
}else{
$status='active';
}
$data= array(
'status' => $status
);
$this->db->where('banner_id',$sid);
return $this->db->update('banner_types',$data);
}
Просмотры banner / banner_list. php
<?php
?>
<?php $session = $this->session->userdata('username');?>
<div class="row m-b-1 animated fadeInRight">
<div class="col-md-4">
<div class="box-content card white ">
<h4 class="box-title">ADD NEW banner TYPE </h4>
<div class="card-body">
<?php $attributes = array('name' => 'add_banner', 'id' => 'xin-form', 'autocomplete' => 'off');?>
<?php $hidden = array('user_id' => $session['user_id']);?>
<?php echo form_open_multipart('admin/banner/add_banner', $attributes, $hidden);?>
<div class="form-body">
<div class="form-group" >
<label for="name">URL</label>
<input class="form-control" placeholder="banner Name" name="banner_url" type="text" value="">
</div>
<div class="form-group" >
<label for="name"> Name</label>
<input class="form-control" placeholder=" Stitching Charge" name="banner_name" type="text" value="">
</div>
<div class="form-group" >
<label for="name">Banner Image </label>
<input type="file" class="form-control-file" id="design_image" name="design_image" onchange="readURL(this);">
<small>Upload files only: gif,png,jpg,jpeg</small>
</div>
</div>
<div class="form-actions"> <?php echo form_button(array('name' => 'hrsale_form', 'type' => 'submit', 'class' => 'btn btn-primary', 'content' => '<i class="fa fa fa-check-square-o"></i> Save')); ?> </div>
<?php echo form_close(); ?> </div>
</div>
</div>
<div class="col-md-8">
<div class="card">
<h4 class="card-header"> List All banner Types </h6>
<div class="card-datatable table-responsive">
<table class="datatables-demo table table-striped table-bordered" id="xin_table">
<thead>
<tr>
<th>URL</th>
<th>Banner Name</th>
<th>Action</th>
<th>Image</th>
<th>Action</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
Активный неактивный статус отображается правильно. Но статус не обновляется, и в консоли нет ошибок.
Я следил за этим для справки активировать деактивировать статус с помощью codeigniter