php物件導向分頁,PHP中物件導向的分頁類

2021-10-25 20:48:48 字數 1917 閱讀 8719

$page = new page(53,10);

$p = $page->rendor();

echo '

';
var_dump($p);

echo'';

* 分頁類

class page

protected $url;            //url

protected $pagecount;  //總頁數

protected $total;      //總條數

protected $num;            //每頁顯示數

protected $page;       //當前頁

//初始化成員屬性

public function __construct($total,$num = 5)

//總條數

$this->total = ($total > 0 )? (int) $total : 1;

//每頁顯示條數

$this->num = $num;

//總頁數

$this->pagecount = $this->getpagecount();

//當前頁

$this->page = $this->getcurrentpage();

//url

$this->url = $this->geturl();

//一次性返回所有的分頁資訊

public function rendor()

return[

'first' => $this->first(),

'next' => $this->next(),

'prev' => $this->prev(),

'end' => $this->end(),

//limit方法,在未來分頁資料查詢的時候,直接返回對應的limit0,5 這樣的字串

public function limit()

$offset = ($this->page - 1)  * $this->num;

$str = $offset.','.$this->num;

return $str;

//首頁,設定page = 1

protected function first()

return $this->setquerystring('page=1');

protected function prev()

$page = ($this->page <= 1) ? 1 : ($this->page - 1);

return $this->setquerystring('page='.$page);

protected function next()

$page = ($this->page >= $this->pagecount) ? $this->pagecount : ($this->page + 1);

return $this->setquerystring('page='.$page);

//首頁

protected function end()

return $this->setquerystring('page='.$this->pagecount);

//一種情況有? 一種情況沒有?

protected function setquerystring($page)

//查詢url中是否有問號

if (stripos($this->url, '?')) else elseelse {

$page = 1;

return $page;

//處理總頁數

protected function getpagecount()

//進一法取整

return ceil($this->total / $this->num);

PHP物件導向

1 什麼是物件導向 起初,物件導向 是專指在程式設計中採用封裝 繼承 抽象等設計方法。可是,這個定義顯然不能再適合現在情況。物件導向的思想已經涉及到軟體開發的各個方面。如 物件導向的分析 ooa,object oriented analysis 物件導向的設計 ood,object oriented...

php物件導向

smarty自定義函式 作用 用於在模板被執行時為模板變數賦值 函式名稱 assign 引數 var 宣告變數名稱 字串 value 給該變數賦值 字串 tpl assign title this is title 實現自定義函式有兩種 1.註冊自定義函式 3.版本不支援 tpl register ...

php物件導向

一 寫出php的public protected private三種訪問控制模式的區別 public 公有,任何地方都可以訪問 protected 繼承,只能在本類或子類中訪問,在其他地方不允許訪問 private 私有,只能在本類中訪問,在其他地方不允許訪問 二 請用單態設計模式方法設計類滿足要求...