thinkCMF----增删改查操作

thinkCMF的增删改查基本操作:

一、增加数据

$res = Db::name('form')->insert($data);

示例代码:

public function index(){
    if(!request()->isPost()){exit('请求错误');};
    $return = array();
    $return['code'] = 1;
    $return['msg'] = "添加成功";
    $data = array();
    $data['username'] = input('username');
    $data['company'] = input('company');
    $data['phone'] = input('phone');
    $data['email'] = input('email');
    $data['time'] = time();
    $data['message'] = input('message');
    $res = Db::name('form')->insert($data);
    if(!$res){
        $return['code'] = 0;
        $return['msg'] = "添加失败";
    };
    exit(json_encode($return));
}

二、删除数据

Db::name('form')->delete($id);

简单示例:

public function del(){
    $id = $this->request->param('id', 0, 'intval');
    Db::name('form')->delete($id);
    $this->success("删除成功!", url("form/index"));
}

三、修改数据

$res = Db::name('model')->update($data);

简单示例:

public function editPost(){
    if(!request()->isPost()){exit('请求错误');};
    $data = $this->request->param();
    $return = array();
    $return['code'] = 1;
    $return['msg'] = '修改成功';
    $res = Db::name('model')->update($data);
    if(!$res){
        $return['code'] = 0;
        $return['msg'] = "修改失败";
    };
    exit(json_encode($return));
}

四、查询数据

$category_list = Db::name('portal_category')->field(array('id','parent_id'))->select();
$ids = Db::name('portal_category_post')->where('category_id','in',$cur_category_ids)->field(array('post_id'))->select();
$categoryinfo = Db::name('portal_category_post')->where('post_id','eq',$id)->field('category_id')->find(); 
$slide = Db::name('slide_item')->where($where)->select();

结合where使用:

$where = array();
$where['id'] = array('in',$all_post_ids_arr);
$where['post_type'] = 1;
$where['post_status'] = 1;
$pagelist_arr = Db::name('portal_post')->where($where)->paginate($limit);

 

转载于:https://www.cnblogs.com/e0yu/p/9541000.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值