糯米文學吧

位置:首頁 > 計算機 > php語言

cakephp的分頁排序

php語言6.63K

在PHP學習過程中你是否感到困惑?以下是本站小編精心為大家整理的PHP教程,希望對大家有所幫助!更多內容請關注應屆畢業生網!

cakephp的分頁排序

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

1 數據表

webkit-user-select: none; border-left-width: 0px !important; box-sizing: content-box !important; overflow: visible !important; width: auto !important; vertical-align: baseline !important; border-bottom-width: 0px !important; right: auto !important; position: static !important; float: none !important; color: rgb(175, 175, 175) !important; outline: invert none 0px !important; padding: 9px 0px 9px 9px !important; left: auto !important; min-height: auto !important; line-height: 1.1em !important; top: auto !important; border-top-width: 0px !important; bottom: auto !important; background: rgb(247, 247, 249);">123456789CREATETABLEIFNOTEXISTS`users`(`id`int(11)NOTNULLAUTO_INCREMENT,`firstname`varchar(32)NOTNULL,`lastname`varchar(32)NOTNULL,`email`varchar(32)NOTNULL,`username`varchar(32)NOTNULL,`password`varchar(32)NOTNULL,PRIMARYKEY(`id`))

2 在app/models/ 中,代碼為:

1234<?phpclassUserextendsAppModel{var$name='User';?>

3 app/controllers/users_中

123456789functionview_users(){$this->paginate=array('limit'=>2);//users用於在前端頁面中顯示$this->set('users',$this->paginate('User'));}

4 頁面模版文件

app/views/users/view_

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273<?phpecho"<pclass='page-title'>Users</p>";//title//this'addnewuser'buttonwillbeusedforthenexttutorialecho"<pstyle='float:right;'>";$url="add/";echo$form->button('AddNewUser',array('onclick'=>"='".$this->Html->url($url)."'"));echo"</p>";echo"<pstyle='clear:both;'></p>";if(sizeOf($users)>0){//checkifthereareuserrecordsreturned?><table><tr><!--第一個參數是表格列的label,第一個參數是排序中實際數據庫的字段--><thstyle='text-align:left;'><?phpecho$paginator->sort('Firstname','firstname');?></th><th><?phpecho$paginator->sort('Lastname','lastname');?></th><th><?phpecho$paginator->sort('Email','email');?></th><th><?phpecho$paginator->sort('Username','username');?></th><th>Action</th></tr><tr><?phpforeach($usersas$user){//wewilloopthroughtherecordstoDISPLAYDATAecho"<tr>";echo"<td>";echo"{$user['User']['firstname']}";echo"</td>";echo"<td>{$user['User']['lastname']}</td>";echo"<td>{$user['User']['email']}</td>";echo"<td>{$user['User']['username']}</td>";echo"<tdstyle='text-align:center;'>";//'Edit'and'Delete'linkherewillbeusedforournexttutorialsecho$html->link('Edit',array('action'=>'edit/'.$user['User']['id']),null,null);echo"/";echo$html->link('Delete',array('action'=>'delete/'.$user['User']['id']),null,'Areyousureyouwanttodeletethisrecord?');echo"</td>";echo"</tr>";}?></tr></table><?php//分頁開始echo"<pclass='paging'>";//第一頁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"</p>";}else{//iftherearenorecordsfound,displaythisecho"<pclass='no-records-found'>NoUsersfound.</p>";}?>

標籤:cakephp 分頁