- 相關推薦
cakephp的分頁排序
在PHP學習過程中你是否感到困惑?以下是百分網小編精心為大家整理的PHP教程,希望對大家有所幫助!更多內容請關注應屆畢業生網!
cakephp中的分頁還是很簡單的,下面例子復習下
1 數據表
|
1
2
3
4
5
6
7
8
9
|
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 中,代碼為:
|
1
2
3
4
|
<?php class User extends AppModel{ var $name = 'User'; ?> |
3 app/controllers/users_controller.php中
|
1
2
3
4
5
6
7
8
9
|
function view_users(){ $this->paginate = array( 'limit' => 2 ); //users用于在前端頁面中顯示 $this->set('users', $this->paginate('User'));} |
4 頁面模版文件中
app/views/users/view_users.ctp
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<?phpecho "<p class='page-title'>Users</p>"; //title//this 'add new user' button will be used for the next tutorialecho "<p style='float:right;'>"; $url = "add/"; echo $form->button('Add New User', array('onclick' => "location.href='".$this->Html->url($url)."'"));echo "</p>";echo "<p style='clear:both;'></p>";if( sizeOf( $users ) > 0 ){ //check if there are user records returned?><table> <tr> <!--第一個參數是表格列的label,第一個參數是排序中實際數據庫的字段--> <th style='text-align: left;'><?php echo $paginator->sort('Firstname', 'firstname'); ?></th> <th><?php echo $paginator->sort('Lastname', 'lastname'); ?></th> <th><?php echo $paginator->sort('Email', 'email'); ?></th> <th><?php echo $paginator->sort('Username', 'username'); ?></th> <th>Action</th> </tr> <tr> <?php foreach( $users as $user ){ //we wil loop through the records to DISPLAY DATA echo "<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 "<td style='text-align: center;'>"; //'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 "</td>"; echo "</tr>"; } ?> </tr></table><?php //分頁開始 echo "<p class='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{ //if there are no records found, display this echo "<p class='no-records-found'>No Users found.</p>";}?> |
【cakephp的分頁排序】相關文章:
word怎樣自動分頁06-23
php分頁類代碼09-08
PHP簡單的分頁過程與原理10-01
學習php分頁代碼實例10-11
html無刷新分頁前端代碼08-20
PHP分頁自定義函數09-08
Word2010如何插入分頁符09-11