Example #1
0
    $c_name = trim($_POST['className']);
    $c_parent_id = trim($_POST['parentId']);
    //合法性验证
    if (empty($c_name)) {
        //如果为空,跳转到添加页面
        redirect('productClass.php?act=add', '分类名不能为空!');
    }
    //合理性验证
    $product = new Product();
    //同一分类下不能有相同的分类名
    if ($product->CheckParentIdAndName($c_name, $c_parent_id)) {
        //存在:自动警告
        redirect('productClass.php?act=add', '分类名:' . $c_name . '重复');
    }
    //插入数据
    if ($product->InsertProduct($c_name, $c_parent_id)) {
        //插入成功
        redirect('productClass.php', '商品插入成功', 1000);
    } else {
        //插入失败
        redirect('productClass.php?act=add', '商品插入失败');
    }
} elseif ($act == 'delete') {
    //接收用户id
    $id = $_GET['id'];
    $product = new Product();
    //此分类不是叶子节点
    if ($product->IsNoleaf($id)) {
        //不是叶子节点,不能删除分类
        redirect('productClass.php', '当前分类下还存在分类,不允许直接删除');
    }