The pagination in cakephp is still very simple, the following example review
1 Data Sheets
CREATE TABLE IF not EXISTS ' users ' ( ' id ' int (one) not null auto_increment, ' firstname ' varchar (+) NOT NULL, ' LastName ' varchar (+) NOT NULL, ' email ' varchar (+) NOT NULL, ' username ' varchar (+) NOT null, ' password ' varchar (+) not NULL, PRIMARY KEY (' id '))
2 in app/models/user.php, the code is:
<?php class User extends appmodel{ var $name = ' User ';?>
3 in app/controllers/users_controller.php
function View_users () { $this->paginate = Array ( ' limit ' = = 2 ); Users are used to display $this->set (' users ', $this->paginate (' User ') in the front-end page;}
4 in a page template file
App/views/users/view_users.ctp
<?phpecho "<div class= ' page-title ' >Users</div>"; Title//this ' Add new User ' button would be used for the next Tutorialecho "<div style= ' float:right; ' > "; $url = "add/"; echo $form->button (' Add New User ', Array (' onclick ' = ' location.href= ' "). $this->html->url ($url)." ' "); echo "</div>"; echo "<div style= ' Clear:both; ' ></div> "; if (SizeOf ($users) > 0) {//check If there is User records returned?><table> <tr> ; <!--The first parameter is the label of the table column, the first parameter is the field of the actual database in the sort--<th style= ' text-align:left; ' ><?php echo $paginator->sort (' Firstname ', ' Firstname ');?></th> <th><?php Echo $paginato R->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 would 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, ' is you sure want to Delete t His record? '); echo "</td>"; echo "</tr>"; }?> </tr></table><?php//page start echo "<div class= ' paging ' >"; The first page of Echo $paginator->first (' primary '); echo ""; Previous if ($paginator->hasprev ()) {echo $paginator->prev (' << '); } echo ""; Specifies the number of pages echo $paginator->numbers (Array (' modulus ' = 2)); echo ""; if ($paginator->hasnext ()) {echo $paginator->next (' >> '); } echo ""; Final page Echo $paginator->last (' last '); echo "</div>"; }else{//if There is no records found, display this echo "<div class= ' no-records-found ' >no Users found.</div& gt; ";}? >