1 app/controllers/users_controller.php
function view_users(){
        $this->paginate = array(
        'limit' => 2
    $this->set('users', $this->paginate('User'));

2 页面模版文件中
echo "<div class='page-title'>Users</div>"; //title

//this 'add new user' button will be used for the next tutorial
echo "<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 are user records returned
         <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>
        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>";

    echo "<div class='paging'>";

      echo $paginator->first('First');
    echo " ";
        echo $paginator->prev('<<');
    echo " ";
    echo $paginator->numbers(array('modulus' => 2));
    echo " ";
        echo $paginator->next('>>');
    echo " ";
    echo $paginator->last('Last');
    echo "</div>";
}else{ //if there are no records found, display this
    echo "<div class='no-records-found'>No Users found.</div>";



posts - 139, comments - 0, trackbacks - 0, articles - 0

Copyright © PHP博客