php分页排序不变化,PHP框架cakephp的分页排序方法

这段代码展示了在CakePHP中如何实现用户数据的分页显示。在`users_controller.php`的`view_users()`函数中,设置分页限制为2条记录,并在视图模板`view_users.ctp`中显示排序和分页的用户信息。包括用户名、姓氏、名字和电子邮件。同时,提供了编辑和删除用户的链接,以及分页导航元素。
摘要由CSDN通过智能技术生成

1 app/controllers/users_controller.php中

function view_users(){

$this->paginate = array(

'limit' => 2

);

//users用于在前端页面中显示

$this->set('users', $this->paginate('User'));

}

2 页面模版文件中

app/views/users/view_users.ctp

echo "

Users
"; //title

//this 'add new user' button will be used for the next tutorial

echo "

";

$url = "add/";

echo $form->button('Add New User', array('onclick' => "location.href='".$this->Html->url($url)."'"));

echo "

";

echo "

if( sizeOf( $users ) > 0 ){ //check if there are user records returned

?>

<?php echo $paginator->sort('Firstname', 'firstname'); ?><?php echo $paginator->sort('Lastname', 'lastname'); ?><?php echo $paginator->sort('Email', 'email'); ?><?php echo $paginator->sort('Username', 'username'); ?>Action

foreach( $users as $user ){ //we wil loop through the records to DISPLAY DATA

echo "

";

echo "

";

echo "{$user['User']['firstname']}";

echo "

";

echo "

{$user['User']['lastname']}";

echo "

{$user['User']['email']}";

echo "

{$user['User']['username']}";

echo "

";

//'Edit' and 'Delete' link here will be used for our next tutorials

echo $html->link('Edit', array('action'=>'edit/'.$user['User']['id']), null, null);

echo " / ";

echo $html->link('Delete', array('action'=>'delete/'.$user['User']['id']), null, 'Are you sure you want to delete this record?');

echo "

";

echo "

";

}

?>

//分页开始

echo "

";

//第一页

echo $paginator->first('First');

echo " ";

//前一页

if($paginator->hasPrev()){

echo $paginator->prev('<

}

echo " ";

//指定页数

echo $paginator->numbers(array('modulus' => 2));

echo " ";

if($paginator->hasNext()){

echo $paginator->next('>>');

}

echo " ";

//最后一页

echo $paginator->last('Last');

echo "

";

}else{ //if there are no records found, display this

echo "

No Users found.
";

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值