ThinkPHP框架学习之CRUD
2016-01-19 00:00
661 查看
User模块UserAction.class.php
首页模板文件index.html
添加表单模板addform.html
<?php class UserAction extends Action { public function index(){ $m=M('User');//操作的数据库表 $arr=$m->select();//查询数据库 $this->assign('data',$arr);// $this->display(); } /* * 向数据库插入数据 **/ public function add(){ $m=M('User'); $m->username=$_POST['username']; $m->sex=$_POST['sex']; $num=$m->add(); if ($num>0){ $this->success('添加成功','index');//添加成功并返回首页 }else { $this->error('添加失败'); } } /* * 显示添加表单 **/ public function addform(){ $this->display(); } } ?>
首页模板文件index.html
<html> <head> <title></title> <script> function jump(){ window.location='__URL__/addform'; } </script> </head> <body> <table border="1"> <tr> <th>ID号</th> <th>用户名</th> <th>性别</th> <th>操作</th> </tr> <volist name='data' id='vo'> <tr> <td>{$vo.id}</td> <td>{$vo.username}</td> <td>{$vo.sex}</td> <td><a href="">删除</a>|<a href="">修改</a></td> </tr> </volist> </table> <button onclick="jump()">添加用户</button> </body> </html>
添加表单模板addform.html
<html> <head> <title></title> </head> <body> <form action='__URL__/add' method='post'> 姓名:<input type='text' name='username' /><br /> 性别:男<input type='radio' name='sex' value='1' checked='true' /> 女<input type='radio' name='sex' value='0' /><br /> <input type='submit' value='添加用户' /> </form> </body> </html>
相关文章推荐
- PHP使用flock实现文件加锁的方法
- PHP错误:Allowed memory size of xxx bytes(一)
- PHP错误:Allowed memory size of xxx bytes(二)
- laravel
- php命名空间与自动加载函数一起使用
- 最新版本 IntelliJ IDEA 15. PyCharm 5. PhpStorm10. WebStorm 11 注册 破解
- 用matplotlib作图步骤
- php文件下载
- SmtpClient 类
- ubuntu下配置NFS,TFTP服务
- PHP 依赖注入 (转)
- kuangbin_ShortPath R (HDU 4370)
- Matplotlib安装感想
- PHP中递归函数的一个常见逻辑问题
- 也说php从mysql数据库通过服务器端json返回数据出现乱码问题
- zend studio12.5破解方法
- PHP学习练手(十五)
- PHP 二进制 pack() unpack()
- PHP中VC6、VC9、TS、NTS版本的区别与用法详解
- 搭建个人博客&论坛(LAMP):wordpress、discuz、phpMyAdmin