public function index($p=1){
$modle=D('News');
$limit=($p-1)*10;//每页显示的数目
$news=$modle->limit("$limit,10")->order('create_time desc')->select();
$count= $modle->count();//算出数据库的数目
$total= ceil($count/10);//总页数
//偏移量开始的位置
$start = $p - 2;
//偏移量结束的位置
$end = $p + 2;
if($p<1)$p=1;
if ($start < 1) {
$start = 1;
$end = min([$total, 5]); //取显示数量与总页数的最小数
}
if($end>$total){
$end=$total;
$start= max($total-4,1);
}
$this->assign([
'news'=>$news,
'total'=>$total,
'start'=>$start,
'end'=>$end,
'p'=>$p,
]);
$this->display();
$modle=D('News');
$limit=($p-1)*10;//每页显示的数目
$news=$modle->limit("$limit,10")->order('create_time desc')->select();
$count= $modle->count();//算出数据库的数目
$total= ceil($count/10);//总页数
//偏移量开始的位置
$start = $p - 2;
//偏移量结束的位置
$end = $p + 2;
if($p<1)$p=1;
if ($start < 1) {
$start = 1;
$end = min([$total, 5]); //取显示数量与总页数的最小数
}
if($end>$total){
$end=$total;
$start= max($total-4,1);
}
$this->assign([
'news'=>$news,
'total'=>$total,
'start'=>$start,
'end'=>$end,
'p'=>$p,
]);
$this->display();
}