厉 害 了!'我的' TP5 !!!

   随着科技的飞快发展,技术的不断更新迭代,TP5"敲敲"来到我们的生活,让我带你ECHO出它的神奇吧!


一  添加/修改/文件上传

public function addPlus(){
        $post=input('post.'); //接值
        $file = request()->file('img'); // 获取表单上传文件img的值
        // 移动到框架应用根目录/public/uploads/ 目录下
        $info = $file->validate(['size'=>15678,'ext'=>'jpg,png,gif'])
                     ->move(ROOT_PATH . 'public' . DS . 'uploads');
        if($info){
            // 成功上传后 获取上传信息
            $post['u_img']= $info->getFilename();

            if(empty($post['u_id'])){
                //添加入库
                $result=db('user')->insert($post);
            }else{
                //修改资料
                $result=db('user')->update($post);
            }
            if($result){
                $this->success('操作成功','listPage');
            }else{
                $this->error('失败');
            }

        }else{
            // 上传失败获取错误信息
            echo $file->getError();
        }
    }

二 查询

function user(){
        $user=db('user');
        $result= $user->where('u_pwd',$pwd)
            ->whereOr('u_name|u_phone',$name)
            ->find();
        echo $user->getLastSql();die;
}
//SELECT * FROM `user` WHERE  (  `u_name` ='YBaog12'  OR `u_phone` = 1379999999 ) AND `u_pwd`='123456';


三 分页

public function listPage(){
        $list = db('user')
            ->where('status',1) //查询条件
            ->order('sort desc') //排序
           ->paginate(10); //每页显示条数
        return   $this->fetch('list',['list'=>$list]);
 

分页前台样式

<style type="text/css">
        .pagination{text-align:center;margin-top:20px;margin-bottom: 20px;}
        .pagination li{margin:0px 10px; border:1px solid #e6e6e6;padding: 3px 8px;display: inline-block;}
        .pagination .active{background-color:#1d53bf;color: #fff;}
        .pagination .disabled{color:#aaa;}
</style>

<div>{$list->render()}</div>

四  删除

public function listDel(){
        $id=input('get.sid'); //获取删除ID
        $del=db('user')->delete($id); //根据主键删除(可以使用 Where)
        if($del){
             unlink('文件的根路径');
            $this->success('删除成功','listPage');
        }else{
            $this->error('失败');
        }
    }
 

JS删除一行

function deleteCurrentRow(obj){
        var tr=obj.parentNode.parentNode;
        var tbody=tr.parentNode;
        tbody.removeChild(tr);
        //只剩行首时删除表格 
//        if(tbody.rows.length==1) {
//            tbody.parentNode.removeChild(tbody);
//        }
    }

<td><button οnclick="deleteCurrentRow(this)">删除</button></td>




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值