博客
关于我
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.php中view_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/

你可能感兴趣的文章
Python函数运行的可执行文件的终端输出如何以一般方式静音?
查看>>
Python+Pytest+Allure+Git+Jenkins接口自动化框架
查看>>
python+pytest接口自动化 —— 参数关联
查看>>
python+pytest接口自动化 —— 参数关联
查看>>
Python+pytest接口自动化 —— 接口测试基础
查看>>
python+pytest接口自动化 —— 自动化用例编写思路 (使用pytest编写一个测试脚本)
查看>>
Python+pytest接口自动化之cookie绕过登录(保持登录状态)
查看>>
python+pytest接口自动化:接口测试
查看>>
Python+requests+unittest执行接口自动化测试详情
查看>>
Python+requests+unittest执行接口自动化测试详情
查看>>
python+requests+unittest执行自动化接口测试!
查看>>
Python+Requests编码识别Bug
查看>>
python函数编写_[零基础学python]传说中的函数编写条规
查看>>
Python+selenium —— UI自动化之鼠标操作
查看>>
python函数注释,参数后面加冒号:,函数后面的箭头→是什么?
查看>>
Python+Selenium+Threading进行兼容性测试
查看>>
Python+selenium+unittest的GUI自动化框架实现
查看>>
python函数拟合不规则曲线_Python计算&绘图——曲线拟合问题(转)
查看>>
python函数定义的基本格式_零基础学python-2.19 定义函数、调用函数与默认参数
查看>>
Python+Selenium之数据驱动测试的实现
查看>>