我想删除一个或多个产品类别的形式tbl_category。
这是控制器的代码:
public function manage_product_category()
{
$data=array();
$data['all_product_category']= $this->ehome_model- >select_all_product_category();
$data['admin_maincontent']=$this->load->view('admin/view_product_category',$data,true);
$this->load->view('admin/admin_master',$data);
}
public function delete_product_category($category_id)
{
$this->super_a_model->delete_product_category_by_category_id($category_id);
redirect('super_admin/manage_product_category');
}这个模型代码:
public function delete_product_category_by_category_id($category_id)
{
$this->db->where('category_id',$category_id);
$this->db->delete('tbl_category');
}发布于 2014-12-16 10:23:10
您需要使用unlink php方法:http://php.net/manual/it/function.unlink.php
$path = base_url.'./images/category_images/'.$file_name;
unlink($path);确保设置正确的$file_name,如果没有,只需对数据库运行一个查询,以便在之前获取文件名以删除该行。
发布于 2014-12-16 11:48:56
检查这个链接单击此处。
$this->load->helper("file");
delete_files($path);发布于 2014-12-20 05:46:55
首先,您必须有一个img_url字段,或者根据您的table.Then中的要求,在第一步中,您需要像这样从表中获取img_url,然后从目录中删除这个字段,
//write this function in your_controller
function delete($your_id)
{
$img_url = $this->your_model->get_image_url($your_id);//this will get the img_url from your_ model
unlink($img_url); //this will delete the image from your directory
$this->your_model->delete_image_record($your_id); //this will delete the record from the table
}
//write the following functions in your_model
function get_image_url($your_id)
{
$this->db->select('your_img_url');
$this->db->from('your_table');
$this->db->where('your_id',(int)$your_id);
$query = $this->db->get();
if($query->num_rows() == 1) return $query->row()->your_img_url;
else return NULL;
}
function delete_image_record($your_id)
{
$this->db->where("$your_id",(int)$your_id);
$this->db->delete('your_table');
}https://stackoverflow.com/questions/27501758
复制相似问题