无线分类编辑 更新时的代码

#根据ID来更新一个商品
public function byid_update(){
#获取页面传过来的id
$id=$this->uri->segment(4);
#根据id来查询出当前分类的子分类
$childs=$this->Category->byid_child($id);
#定义一个空数组
$array=array();
#循环读取放入到数组中
foreach ($childs as $child){
$array[]=$child['cat_id'];
}
//获取父类id
$parent_id=$this->input->post('parent_id');
#如果选中的是父类是自己本身或者选中的是自己的后代节点则是无效的 因为这样会使这条链断开
if($id==$parent_id||in_array($parent_id, $array)){
$data['url']=site_url('admin/Category/edit').'/'.$id;
$data['message']='不能将分类放入当前分类或者其子分类中!';
$data['wait']=1;
$this->load->view('message.html',$data);
}else{
#获取页面post传过来的数据 定义一个数组来接收
$data=array(
'cat_name'=>$this->input->post('cat_name'),
'parent_id'=>$parent_id,
'cat_desc'=>$this->input->post('cat_desc'),
'sort_order'=>$this->input->post('sort_order'),
'unit'=>$this->input->post('unit'),
'is_show'=>$this->input->post('is_show')
);
#调用模型层
$result=$this->Category_Model->byid_update($id,$data);
echo $result;
#判断是否更新成功
if($result>0){
$data['url']=site_url('admin/Category/index');
$data['message']='更新成功!';
$data['wait']=1;
$this->load->view('message.html',$data);
}else{
$data['url']=site_url('admin/Category/index');
$data['message']='更新失败!';
$data['wait']=1;
$this->load->view('message.html',$data);
}
}

}

原文地址:https://www.cnblogs.com/hgj123/p/3666486.html