怎么进行增删改查
发布网友
发布时间:2022-04-24 06:32
我来回答
共1个回答
热心网友
时间:2022-06-16 23:31
public function add(){
import('Class.Category', APP_PATH);
$cate = M('article_cate')-> where(array('del'=>0))-> order('sort')->select();
$cate = Category::catesort($cate);
//p($cate); die;
$this->cate = $cate;
$this -> display();
}
//添加post
public function postadd(){
if(!IS_POST) halt('页面不存在');
$typeid = I('typeid');
if(get_is_type_1($typeid)==1){
$this->error('添加失败,当前栏目模式为单页');
exit();
}
if(get_is_type_1($typeid)==2){
$this->error('添加失败,当前栏目模式为外链');
exit();
}
if(I('title')==''){
$this->error('添加失败!标题不能为空');
}
if(I('typeid')==0){
$this->error('添加失败!请选择分类');
}
if(I('content')==''){
$this->error('添加失败!内容不能为空');
}
$data = array(
'uid' => session('userid'),
'title' => I('title'),
'keywords' => I('keywords'),
'description' => I('description'),
'typeid' => I('typeid'),
'upimg' => I('upimg'),
'upimgs' => get_imgs($_POST['content']),
'body' => I('content'),
'top' =>I('top'),
'is_music'=>I('is_music'),
'click' => I('click'),
'sendtime' => time(),
'ip' => get_client_ip()
);
if (M('article')->add($data)){
$this->success('添加成功', U(GROUP_NAME . '/Warticle/index'));
}else{
$this->error('添加失败');
}
}
//edit
public function edit(){
import('Class.Category', APP_PATH);
$cate = M('article_cate')-> where(array('del'=>0))-> order('sort')->select();
$cate = Category::catesort($cate);
$this->cate = $cate;
$id = I('id', 0, 'intval');
$id=$this->_get('id');
$db = M('article');
$article = $db->where(array('id' => $id))->find();
if ($article){
$this-> article = $article;
$this->display();
}else{
$this->error('参数错误');
}
}
//upedit
Public function upedit(){
if(!IS_POST) halt('页面不存在');
$id = (int)$_GET['id'];
$typeid = I('typeid');
if(get_is_type_1($typeid)==1){
$this->error('添加失败,当前栏目模式为单页');
exit();
}
if(get_is_type_1($typeid)==2){
$this->error('添加失败,当前栏目模式为外链');
exit();
}
if(I('title')==''){
$this->error('添加失败!标题不能为空');
}
if(I('typeid')==0){
$this->error('添加失败!请选择分类');
}
if(I('content')==''){
$this->error('添加失败!内容不能为空');
}
$data = array(
'title' => I('title'),
'keywords' => I('keywords'),
'description' => I('description'),
'typeid' => I('typeid'),
'upimg' => I('upimg'),
'upimgs' => get_imgs($_POST['content']),
'body' => I('content'),
'top' =>I('top'),
'is_music'=>I('is_music'),
'click' => I('click')
);
$db = M('article');
$activities = $db->where("id = $id")->save($data);
if($activities){
$this->success('恭喜您!修改成功', U(GROUP_NAME . '/Warticle/index'));
}else{
$this->error('修改失败!');
}
}
//删除
public function del(){
if (!IS_AJAX) halt('页面不存在');
$id = (int)I('id');
$data = array(
'del'=>1,
);
$del = M('article')->where(array('id' => $id))->save($data);
if($del){
$this->ajaxReturn(array('status'=>1),'json');
}else{
$this->ajaxReturn(array('status'=>0),'json');
}
}