菜单的编辑于删除功能

Original 2019-05-17 10:19:46 226
abstract:后台php代码   添加: public function add(){     $pid = (int)input('get.pid');     $mid = (int)input('get.mid');
后台php代码  
添加:
public function add(){
    $pid = (int)input('get.pid');
    $mid = (int)input('get.mid');
    $data['parent_menu'] = $this->db->table('admins_menu')->where(array('mid'=>$pid))->item();
    $data['menu'] = $this->db->table('admins_menu')->where(array('mid'=>$mid))->item();
    return $this->fetch('',$data);
}

删除:
public function delete(){
    $mid = (int)input('post.mid');
    $res = $this->db->table('admins_menu')->where(array('mid'=>$mid))->delete();
    if(!$res){
        exit(json_encode(array('code'=>1,'msg'=>'删除失败')));
    }
    exit(json_encode(array('code'=>0,'msg'=>'删除成功')));
}


前台异步调用javascript代码:

function add(mid){
    var pid = $('#pid').val();
    layer.open({
        type:2,
        title:mid>0?'编辑菜单':'添加菜单',
        shade:0.3,
        area:['480px','420px'],
        content:'/index.php/admins/menu/add?mid='+mid+'&pid='+pid
    });
}

function del(mid){
    layer.confirm('确定要删除吗?',{
        icon:3,
        btn:['确定','取消']
    },function(){
        $.post('/index.php/admins/menu/delete',{'mid':mid},function(res){
            if(res.code>0){
                layer.alert(res.msg,{'icon':2});
            }else{
                layer.msg(res.msg,{'icon':1});
                setTimeout(function(){window.location.reload();},1000);
            }
        },'json');
    });
}


Correcting teacher:天蓬老师Correction time:2019-05-17 17:48:20
Teacher's summary:(int)input('get.pid'); 推荐使用 intval()函数代码这种强制转换

Release Notes

Popular Entries