zoukankan      html  css  js  c++  java
  • thinkphp curd操作

    <?php
    class FormAction extends Action{
        public function insert(){
            $Form=D('think_form');
            if($Form->create()) {
                $result =$Form->add();
                if($result) {
                    $this->success('操作成功!');
                }else{
                    $this->error('写入错误!');
                }
            }else{
                $this->error($Form->getError());
            }
        }
        public function read($id=5){
            $Form=M("think_form");
            $data=$Form->find($id);
            if ($data) {
                $this->data=$data;
            }else{
                $this->error("数据错误");
            }
            $this->display();
        }
        public function edit($id=0){
            $Form=M("think_form");
            $this->vo=$Form->find($id);
            $this->display();
        }
        public function update(){
            $Form=D("think_form");
            if ($Form->create()) {
                $result=$Form->save();
                if ($result) {
                    $this->success("操作成功!");
                }else{
                    $this->error("写入错误!");
                }
            }else{
                $this->error($Form->getError());
            }
        }
    }
    ?>

    add html文件:

    <FORM method="post" action="__URL__/insert">
    标题:<INPUT type="text" name="title"><br/>
    内容:<TEXTAREA name="content" rows="5" cols="45"></TEXTAREA><br/>
    <INPUT type="submit" value="提交">
    </FORM>

    read文件:

    <!DOCTYPE HTML>
    <html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    <table>
    <tr>
        <td>id:</td>
        <td>{$data.id}</td>
    </tr>
    <tr>
        <td>标题:</td>
        <td>{$data.title}</td>
    </tr>
    <tr>
        <td>内容:</td>
        <td>{$data.content}</td>
    </tr>
    </table>
    </body>
    </html>

    edit文件:

    <!DOCTYPE HTML>
    <html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
      <FORM method="post" action="__URL__/update">
        标题:<INPUT type="text" name="title" value="{$vo.title}"><br/>
        内容:<TEXTAREA name="content" rows="5" cols="45">{$vo.content}</TEXTAREA><br/>
        <INPUT type="hidden" name="id" value="{$vo.id}">
        <INPUT type="submit" value="提交">
      </FORM>
    </body>
    </html>
  • 相关阅读:
    iframe中的页面如何触发父页面事件
    js获取gridview的值
    不出现重复数字,带干扰的验证码
    文本框内不允许输入字母
    后台调用前台JS方法
    在后台得到前台元素,给元素改变属性值或添加属性
    C#常见面试题
    Flex代码生成器 (FCG)
    c#(WinForm)遍历局域网计算机(电脑)获取IP和计算机名称
    VisualSVN Server + Tortoise SVN 使用教程(补充版)
  • 原文地址:https://www.cnblogs.com/wangwenfei/p/php_thinkphp.html
Copyright © 2011-2022 走看看