我有这个奇怪的问题,可能是我错过了代码中的某些内容。
当我删除图像时,它会被删除,但会保留在页面上。我知道这一点,因为当我刷新页面时它不再存在。
但我想要的是在执行删除功能时以某种方式自动重新加载页面,因为如果用户再次删除(删除的图像),这将显示错误。
控制器:
function property_image_delete() {
if ($this->session->userdata('is_logged_in')) {
$username = $this->session->userdata('v_member_username');
$id = $this->uri->segment(3);
$image = $this->uri->segment(4);
$data['images_urls'] = $this->my_listings_model->get_property_all_images_url($id);
$result = $this->my_listings_model->get_property_all_images_url($id);
if (count($result) > 1) {
$this->my_listings_model->delete_selected_property_image($id, $image, $data);
$data['title'] = 'Image Deleted';
$this->load->model('admin/my_profile_model');
$this->load->view('headfoot/header-dashboard', $data);
} else {
$data['title'] = 'Error';
$this->load->model('admin/my_profile_model');
$data['error_no_delete'] = 'Can\'t delete it! There should be minimum 1 image left.';
$this->load->view('headfoot/header-dashboard', $data);
}
} else // Some Code
型号:
function get_property_all_images_url($id) {
$this->db->select('property_images');
$this->db->from('vbc_property_images');
$this->db->where('property_ref_id', $id);
$query = $this->db->get();
$query_result = $query->result_array();
if (empty($query_result)) {
return FALSE;
} elseif (count($query_result) > 1) {
return 0;
} else{
$rowId = explode(',',$query_result[0]['property_images']);
return $rowId;
}
}
function delete_selected_property_image($id, $image, $data) {
$delete = $image;
$newColumn = '';
foreach ($data['images_urls'] as $key => $value) {
if ($value != $delete) {
$newColumn[] = $value;
}
}
$newUpdatedData = implode(",", $newColumn);
$this->db->where('property_ref_id', $id);
$this->db->set(array('property_images'=>$newUpdatedData));
$this->db->update('vbc_property_images');
unlink('uploads/property-images/'.$image);
return TRUE;
}
有没有办法可以自己刷新页面?