Browse Source

article api

master
林一峰 7 years ago
parent
commit
e9d93f6f7e
  1. 36
      app/Http/Controllers/Api/ArticleController.php
  2. 2
      app/Http/Model/Article.php

36
app/Http/Controllers/Api/ArticleController.php

@ -61,4 +61,40 @@ class ArticleController extends CommonController
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//添加
public function articleAdd(Request $request)
{
if(Helper::isPostRequest())
{
return $this->getLogic()->add($_POST);
}
}
//修改
public function articleUpdate(Request $request)
{
if($request->input('id',null)!=null){$id = $request->input('id');}else{$id='';}if(preg_match('/[0-9]*/',$id)){}else{return ReturnData::create(ReturnData::PARAMS_ERROR);}
if(Helper::isPostRequest())
{
unset($_POST['id']);
$where['id'] = $id;
return $this->getLogic()->edit($_POST,$where);
}
}
//删除
public function articleDelete(Request $request)
{
if($request->input('id',null)!=null){$id = $request->input('id');}else{$id='';}if(preg_match('/[0-9]*/',$id)){}else{return ReturnData::create(ReturnData::PARAMS_ERROR);}
if(Helper::isPostRequest())
{
unset($_POST['id']);
$where['id'] = $id;
return $this->getLogic()->del($where);
}
}
}

2
app/Http/Model/Article.php

@ -184,7 +184,7 @@ class Article extends BaseModel
if($where){$res = $res->where($where);}
if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
$res = $res->find();
$res = $res->first();
return $res;
}

Loading…
Cancel
Save