ThinkPHP
来源:互联网 发布:大学排课软件 编辑:程序博客网 时间:2024/05/16 18:31
<?phpnamespace Home\Controller;use Think\Controller;class NewsController extends Controller { public function add(){ if(IS_POST){ $post = I('post.'); $res = D('news')->add($post); if($res){ $this->success('添加成功','show'); }else{ $this->error('添加失败'); } }else{ $this->display(); } } public function show(){ $s_title = I('get.s_title'); $s_content = I('get.s_content'); $search = array('s_title'=>$s_title, 's_content'=>$s_content); $News = M('news'); // 实例化News对象 // 查询满足要求的总记录数 $count = $News->where("title like '%$s_title%' and content like '%$s_content%'")->count(); // 实例化分页类 传入总记录数和每页显示的记录数(4) $Page = new \Think\Page($count,4); $show = $Page->show();// 分页显示输出 // 进行分页数据查询 注意limit方法的参数要使用Page类的属性 $list = $News->where("title like '%$s_title%' and content like '%$s_content%'")->limit($Page->firstRow.','.$Page->listRows)->select(); $this->assign('search',$search); $this->assign('data',$list);// 赋值数据集 $this->assign('page',$show);// 赋值分页输出 $this->display(); // 输出模板 }}
add.html
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>添加</title></head><body> <center> <form action="__URL__/add" method="post"> <table> <tr> <td>标题</td> <td><input type="text" name="title"></td> </tr> <tr> <td>内容</td> <td><textarea name="content" id="" cols="30" rows="10"></textarea></td> </tr> <tr> <td></td> <td><input type="submit" value="添加"></td> </tr> </table> </form> </center></body></html>
show.html
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>展示</title></head><body> <center> <div> <form action="__URL__/show" method="get"> 标题:<input type="text" name="s_title" value="{$search.s_title}"> 内容:<input type="text" name="s_content" value="{$search.s_content}"> <input type="submit" value="搜索"> </form> </div> <table border="1"> <tr> <th>id</th> <th>标题</th> <th>内容</th> </tr> <if condition="empty($data) neq false"> <td colspan="3">没有该数据。。。。。。。。。。。</td> <else /> <foreach name="data" item="v"> <tr> <td>{$v.id}</td> <td>{$v.title}</td> <td>{$v.content}</td> </tr> </foreach> </if> </table> <div>{$page}</div> <a href="__URL__/add"><button>添加</button></a> </center></body></html>
阅读全文
0 0
- thinkphp
- thinkphp
- ThinkPHP
- Thinkphp
- ThinkPHP
- thinkphp
- ThinkPHP
- THINKPHP
- thinkphp
- thinkphp ....
- thinkphp
- thinkphp
- thinkPhp
- thinkphp
- thinkphp
- thinkphp
- ThinkPHP
- thinkphp
- 公司招聘技术的技巧(程序员成长之路)
- 自定义alert弹出框
- HashMap类
- Linux IO模式及 select、poll、epoll详解
- vuex action mutation终于明白
- ThinkPHP
- angular config路由配置
- java反转字符串,不改变标点符号位置,多空格显示为一个的最优写法
- 《技术之瞳》 -- 计算机组成原理 -- 习题 2.32
- IntelliJ IDEA 乱码解决方案 (项目代码、控制台等)
- ZigBee协议栈OSAL解析(第三天)
- linux shell 文件表达式
- Beanstalkd介绍
- NSArray 排序汇总