コード例 #1
0
ファイル: cate.php プロジェクト: lughong/shop
 public function act()
 {
     $fid = isset($_POST['fid']) ? $_POST['fid'] + 0 : '0';
     $cate_name = isset($_POST['cate_name']) ? htmlspecialchars($_POST['cate_name']) : '';
     if (!$cate_name) {
         $msg['error'] = '-1';
         $msg['msg'] = '分类名不能为空';
         echo json_encode($msg);
         throw new Exception('exit');
     }
     //判断是否已经存在
     $is_exists = CateM::getCateInfoByCateName($cate_name);
     if (!$is_exists) {
         $data['fid'] = $fid;
         $data['cate_name'] = $cate_name;
         $rs = CateM::add($data);
         $msg['error'] = "{$rs}";
         $msg['msg'] = '添加成功';
     } else {
         $msg['error'] = '-2';
         $msg['msg'] = '该分类已经存在';
     }
     echo json_encode($msg);
     throw new Exception('exit');
 }