博客
关于我
cakephp的分页排序
阅读量:120 次
发布时间:2019-02-26

本文共 1662 字,大约阅读时间需要 5 分钟。

cakephp中的分页功能实现相对简单易用。本文将从数据库表结构、模型文件和控制器配置等方面详细介绍CakePHP分页的实现方法。

首先,数据库表结构的设计需要考虑到数据的存储和查询效率。以下是一个典型的用户数据表结构示例:

CREATE TABLE IF NOT EXISTS `users` (    `id` int(11) NOT NULL AUTO_INCREMENT,    `firstname` varchar(32) NOT NULL,    `lastname` varchar(32) NOT NULL,    `email` varchar(32) NOT NULL,    `username` varchar(32) NOT NULL,    `password` varchar(32) NOT NULL,    PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

接下来,在应用程序的模型文件中,定义用户模型类。以下是app/models/user.php的代码示例:

在控制器文件中,配置分页功能。以下是app/controllers/users_controller.phpview_users方法的代码:

function view_users() {    $this->paginate = array(        'limit' => 2    );    $this->set('users', $this->paginate('User'));}

最后,在视图文件中,整合分页功能。以下是app/views/users/view_users.ctp的代码示例:

Users";$url = "add/";?>
button('Add New User', array('onclick' => "location.href='" . $this->Html->url($url) . "'")); ?>
0) { ?>
sort('Firstname', 'firstname'); ?>
sort('Lastname', 'lastname'); ?>
sort('Email', 'email'); ?>
sort('Username', 'username'); ?>
Action
link('Edit', array('action' => 'edit/' . $user['User']['id'])); ?> /
link('Delete', array('action' => 'delete/' . $user['User']['id']), null, 'Are you sure you want to delete this record?'); ?>
No Users found.

转载地址:http://hmsf.baihongyu.com/

你可能感兴趣的文章
npm安装crypto-js 如何安装crypto-js, python爬虫安装加解密插件 找不到模块crypto-js python报错解决丢失crypto-js模块
查看>>
npm安装教程
查看>>
npm报错Cannot find module ‘webpack‘ Require stack
查看>>
npm报错Failed at the node-sass@4.14.1 postinstall script
查看>>
npm报错File to import not found or unreadable: @/assets/styles/global.scss.
查看>>
npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
查看>>
npm的安装和更新---npm工作笔记002
查看>>
npm的常用配置项---npm工作笔记004
查看>>
npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
查看>>
npm编译报错You may need an additional loader to handle the result of these loaders
查看>>
npm设置淘宝镜像、升级等
查看>>
npm配置安装最新淘宝镜像,旧镜像会errror
查看>>
npm错误 gyp错误 vs版本不对 msvs_version不兼容
查看>>
npm错误Error: Cannot find module ‘postcss-loader‘
查看>>
npm,yarn,cnpm 的区别
查看>>
NPOI之Excel——合并单元格、设置样式、输入公式
查看>>
NPOI利用多任务模式分批写入多个Excel
查看>>
NPOI在Excel中插入图片
查看>>
NPOI将某个程序段耗时插入Excel
查看>>
NPOI格式设置
查看>>