1 app/controllers/users_controller.php中
function view_users(){
$this->paginate = array(
'limit' => 2
);
//users用于在前端页面中显示
$this->set('users', $this->paginate('User'));
}
2 页面模版文件中
app/views/users/view_users.ctp
echo "
//this 'add new user' button will be used for the next tutorial
echo "
$url = "add/";
echo $form->button('Add New User', array('onclick' => "location.href='".$this->Html->url($url)."'"));
echo "
echo "
if( sizeOf( $users ) > 0 ){ //check if there are user records returned
?>
<?php echo $paginator->sort('Firstname', 'firstname'); ?> | <?php echo $paginator->sort('Lastname', 'lastname'); ?> | <?php echo $paginator->sort('Email', 'email'); ?> | <?php echo $paginator->sort('Username', 'username'); ?> | Action |
---|
foreach( $users as $user ){ //we wil loop through the records to DISPLAY DATA
echo "
";echo "
";echo "{$user['User']['firstname']}";
echo "
";echo "
{$user['User']['lastname']}";echo "
{$user['User']['email']}";echo "
{$user['User']['username']}";echo "
";//'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 "
";echo "
";}
?>
//分页开始
echo "
//第一页
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 "
}else{ //if there are no records found, display this
echo "
}
?>