public function alist() { $this->validateLogin(); $this->createurl(); $article = M('article'); $page = I('get.page'); $perpage = 20; $page = (isset($page) && ($page>0)) ? $page : 1;//current page $last = $page - 1; $next = $page + 1; $url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?page="; $sum = count($article->where("is_delete=0")->select()); $pages = ceil($sum/$perpage); $this->assign('sum',$sum); $this->assign('pages' ,$pages); if ($page > 1) { $arr = "<a href='" . $url . "1''>首頁</a>"; $arr .= "<a href='" . $url . $last . "''>上一頁</a>"; } else { $arr = "<a href='javascript:void(0)' class='noallow'>首頁</a>"; $arr .= "<a href='javascript:void(0)' class='noallow'>上一頁</a>"; } if ( ($page-2)>0 ) { $arr .= "<a href='" . $url . $last . "'' class=\"number\">" . ($page-2) . "</a>"; $arr .= "<a href='" . $url . $last . "'' class=\"number\">" . ($page-1) . "</a>"; } else if( (($page-2)<=0) && (($page-1)>0) ) { $arr .= "<a href='" . $url . $last . "'' class=\"number\">" . ($page-1) . "</a>"; } $arr .= "<a href='" . $url . $last . "'' class=\"number current\">" . ($page) . "</a>"; if ( ($page+1)<=$pages ) { $arr .= "<a href='" . $url . $next . "'' class=\"number\">" . ($page+1) . "</a>"; if ( ($page+2)<=$pages ) { $arr .= "<a href='" . $url . $next . "'' class=\"number\">" . ($page+2) . "</a>"; } } if ($page < $pages) { $arr .= "<a href='" . $url . $next . "''>下一頁</a>"; $arr .= "<a href='" . $url . $pages . "''>尾頁</a>"; } else { $arr .= "<a href='javascript:void(0)' class='noallow'>下一頁</a>"; $arr .= "<a href='javascript:void(0)' class='noallow'>尾頁</a>"; } $this->assign('page',$arr); $data = $article->where("is_delete=0")->page($page,$perpage)->select(); $this->assign('article',$data); $this->display(); }