zoukankan      html  css  js  c++  java
  • thinkphp crud实例代码

    class IndexAction extends Action {
        // 查询数据
        public function index() {
            $Form = M("Form");
            $list = $Form->limit(3)->order('id desc')->select();
            $this->list =  $list;
            $this->display();
        }
        // 写入数据
        public function insert() {
            $Form = D("Form");
            if ($vo = $Form->create()) {
                $list = $Form->add();
                if ($list !== false) {
                    $this->success('数据保存成功!',U('Index/index'));
                } else {
                    $this->error('数据写入错误!');
                }
            } else {
                $this->error($Form->getError());
            }
        }
        // 更新数据
        public function update() {
            $Form = D("Form");
            if ($vo = $Form->create()) {
                $list = $Form->save();
                if ($list !== false) {
                    $this->success('数据更新成功!',U('Index/index'));
                } else {
                    $this->error("没有更新任何数据!");
                }
            } else {
                $this->error($Form->getError());
            }
        }
        // 删除数据
        public function delete($id) {
            if (!empty($id)) {
                $Form = M("Form");
                $result = $Form->delete($id);
                if (false !== $result) {
                    $this->success('删除成功!');
                } else {
                    $this->error('删除出错!');
                }
            } else {
                $this->error('ID错误!');
            }
        }
        // 编辑数据
        public function edit($id) {
            if (!empty($id)) {
                $Form = M("Form");
                $vo = $Form->getById($id);
                if ($vo) {
                    $this->vo   =   $vo;
                    $this->display();
                } else {
                    $this->error('数据不存在!');
                }
            } else {
                $this->error('数据不存在!');
            }
        }
     }
  • 相关阅读:
    深入Python(一)
    深入Python(二)
    初识Python(五)
    初识Python(一)
    深入Python(三)
    一、MongoDB的下载、安装与部署
    浏览器上的javascript
    javascript中的事件
    扩展方法
    团队项目开题报告
  • 原文地址:https://www.cnblogs.com/wordblog/p/6358168.html
Copyright © 2011-2022 走看看