CakePHP's Paging sort

Source: Internet
Author: User
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&gt       ; <!--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; ";}? >
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.