cakephp的分頁排序

巴扎黑
發布: 2016-11-23 15:45:03
原創
1197 人瀏覽過

cakephp中的分頁還是很簡單的,下面例子複習下 

1 資料表 

  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`) 
)
登入後複製

2 在app/models/user.php 中,程式碼為: 

 
登入後複製


function view_users(){
    
        $this->paginate = array(
        'limit' => 2
    );
    
   //users用于在前端页面中显示 
    $this->set('users', $this->paginate('User'));
}
登入後複製

4 頁面模版檔案中 
app/views/users/view_users.ctp 

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 ?> "; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } ?>
sort('Firstname', 'firstname'); ?> sort('Lastname', 'lastname'); ?> sort('Email', 'email'); ?> sort('Username', 'username'); ?> Action
"; echo "{$user['User']['firstname']}"; echo "{$user['User']['lastname']}{$user['User']['email']}{$user['User']['username']}"; //'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 $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.
"; } ?>
登入後複製



相關標籤:
php
來源:php.cn
上一篇:PHP mysql 事務處理實例 下一篇:PHP7參數、數組和Zvals
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
最新問題
相關專題
更多>
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!