thinkphp UserAction.class.php 增删改查

<?php
    class UserAction extends Action{
        public function index(){
            $m=M('User');
            $arr=$m->select();
            //var_dump($arr);
            $this->assign('data',$arr);
            $this->display();
        }
        public function del(){
            $m=M('User');
            $id=$_GET['id'];
            $count=$m->delete($id);
            if($count>0){
                $this->success('数据删除成功');
            }else{
                $this->error('数据删除失败');
            }
        }
        /*
         *    显示修改页面
         * */
        public function modify(){
            $id=$_GET['id'];
            $m=M('User');
            $arr=$m->find($id);
            $this->assign('data',$arr);
            $this->display();
        }
        public function update(){
            $m=M('User');
            $data['id']=$_POST['id'];
            $data['username']=$_POST['username'];
            $data['sex']=$_POST['sex'];
            $count=$m->save($data);
            if($count>0){
                $this->success('数据修改成功','index');
            }else{
                $this->error('数据修改失败');
            }
        }
        /*
         * 添加页面
         * */
        public function add(){
            $this->display();
        }
        public function create(){
            $m=M('User');
            $m->username=$_POST['username'];
            $m->sex=$_POST['sex'];
            $idNum=$m->add();
            if($idNum>0){
                $this->success('数据添加成功','index');
            }else{
                $this->error('数据添加失败');
            }
        }
        //编写search方法,实现搜索
        public function search(){
            //获取post的数据,根据数据组装查询的条件,根据条件从数据库中获取数据,返回给页面中遍历
            if(isset($_POST['username']) && $_POST['username']!=null){
                $where['username']=array('like',"%{$_POST['username']}%");
            }
            if(isset($_POST['sex']) && $_POST['sex']!=null){
                $where['sex']=array('eq',$_POST['sex']);
            }
            $m=M('User');
            $arr=$m->where($where)->select();
            $this->assign('data',$arr);
            $this->display('index');
        }
    
    }
?>

转载于:https://my.oschina.net/shunshun/blog/135311

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值