ThinkPHP 分页
2015-11-10 10:09
573 查看
话不多说,代码如下:
1、mysql
2、模型文件userModel.class.php
3、Action控制器代码
4、视图模板文件index.html
1、mysql
CREATE TABLE `joys_user` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(150) NOT NULL, `password` varchar(100) NOT NULL, `name` varchar(255) NOT NULL, `email` varchar(100) NOT NULL, `reg_date` datetime NOT NULL, `last_login_date` datetime NOT NULL, `active` tinyint(1) NOT NULL, `params` text NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), UNIQUE KEY `email` (`email`), KEY `name` (`name`) ) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; INSERT INTO `joys_user` VALUES ('3', 'admin', '123456', 'administrator', 'aba@qq.com', '0000-00-00 00:00:00', '2015-11-10 09:32:58', '1', ''); INSERT INTO `joys_user` VALUES ('6', 'u1', 'e10adc3949ba59abbe56e057f20f883e', 'user1', 'user1@120.com', '2015-11-10 09:45:28', '0000-00-00 00:00:00', '1', ''); INSERT INTO `joys_user` VALUES ('4', 'alex', '123456', 'alexma', 'alex0018@126.com', '0000-00-00 00:00:00', '2015-10-29 17:25:13', '1', ''); INSERT INTO `joys_user` VALUES ('7', 'u2', '123456', 'user2', 'user2@120.com', '2015-11-10 09:46:46', '0000-00-00 00:00:00', '1', ''); INSERT INTO `joys_user` VALUES ('8', 'u3', '123456', 'user3', 'user3@120.com', '2015-11-10 09:47:18', '0000-00-00 00:00:00', '1', ''); INSERT INTO `joys_user` VALUES ('9', 'u4', '123456', 'user4', 'user4@120.com', '2015-11-10 09:47:51', '0000-00-00 00:00:00', '1', '');
2、模型文件userModel.class.php
.......
3、Action控制器代码
class UserAction extends CommonAction{ function index(){ import('ORG.Util.Page'); $user = new UserModel(); //数据分页 $count = $user->count(); $page = new Page($count,5);//C()获取配置文件的设置 $show = $page->show(); $this->assign('show',$show); //根据分页信息提取数据 $list = $user->order('id')->limit($page->firstRow.','.$page->listRows)->select(); $this->assign('ulist',$list); $this->display(); } }
4、视图模板文件index.html
<table border="1" bordercolor="black" width="100%"> <tr><th>用户名</th><th>昵称</th><th>是否激活</th><th>ID</th></tr> <volist name="ulist" id="user"> <tr> <td><a href="__URL__/edit/id/{$user['id']}">{$user['username']}</a></td> <td>{$user['name']}</td> <td>{$user['active']}</td> <td>{$user['id']}</td> </tr> </volist> </table> {$show}
相关文章推荐
- 自学php-字符串操作2
- ThinkPHP快速入门5_循环和控制输出,公共模板和模板布局
- phpstorm/webstorm/idea 出现一只刷新缓存Updating Index
- Swoole-真正的PHP Web开发框架
- PHP关于依赖注入(控制反转)的解释和例子说明
- sftp
- php中函数的实参和形参
- PHP可变变量,预定义变量,综述,$_GET数组
- PHP图片识别成文字
- install and run tftp dhcp nfs server
- 【转】CI去掉index.php
- 在PHP中使用FastCGI解析漏洞及修复方案
- 深入理解PHP内核(一)
- 深入理解PHP内核(二)之SAPI探究
- 如何使用PHP Embed SAPI实现Opcodes查看器
- php实现可运算的验证码
- 谈谈你对Zend SAPIs(Zend SAPI Internals)的理解
- 深入php内核之php in array
- PHP设计模式之:单例模式
- thinphp 自定义标签,非常方便在模板读取数据。