添加頁插件類:
/** * 分頁 * */ class Custom_Controller_Plugin_Page extends Zend_Controller_Plugin_Abstract { public $pagelimit;//一頁有多少行 public $pagesum; //總行數 public $pageid; //當前頁數 public $dbtable; //數據表類 public $pages; //總頁數 public $rs; //當前頁數據 public $pagebegin; //分部分 開始 public $pageend; //結束 public $prevpage; //上一頁 public $nextpage; //下一頁 public $pagestep = 5; public $where = ''; //條件 public $urlparam = null; //擴展傳遞變量附加到url中 public function __construct($pageid,$pagelimit=null,$db, array $param = null){ $this->dbtable = $db; $db=$db->getAdapter(); if(isset($param)){ $w = null; if(is_array($param)){ foreach ($param as $key=>$value){ $this->urlparam .= '/'.$key.'/'.$value; $w[] = $db->quoteInto($key.' = ?',$value); } } $this->where .= implode(' and ',$w); $this->pagesum = $db->fetchOne('select count(*) from '.$this->dbtable->getTable().' where '.$this->where); } else{ $this->pagesum = $db->fetchOne('select count(*) from '.$this->dbtable->getTable()); } if ($this->pagesum == 0) { return false; } $this->pagelimit =$pagelimit; $this->pages = ceil($this->pagesum/$this->pagelimit); if($pageid<1 || $pageid>$this->pages){ $smartyview = Zend_Registry::get('smartyview'); $smartyview->error ='錯誤的頁碼!'; echo $smartyview->render('error.html'); exit; } $this->pageid =$pageid; $this->prevpage = $pageid -1; $this->nextpage = $pageid +1; if ($pageid == 1) { $this->pagebegin = 1; } else{ $this->pagebegin = $pageid - floor($this->pagestep/2); } if($this->pagebegin < 1){ $this->pagebegin = 1; } $this->pageend = $pageid + floor($this->pagestep/2); if ($this->pageend<$this->pagestep){ $this->pageend = $this->pagestep; } if($this->pageend>$this->pages){ $this->pageend = $this->pages; } } /** * 得到數據數組 * * @param string $order * @return array */ public function getArray($order=null){ if ($this->pagesum == 0) { return false; } $db =$this->dbtable->getAdapter(); $limit = $this->pagelimit; $offset = ($this->pageid - 1)*$this->pagelimit; if ($this->where == ''){ $where = ''; } else { $where = ' where '.$this->where; } if ($order == null) { $rs = $db->fetchAll('select * from '.$this->dbtable->getTable().$where.' limit '.$limit.' offset '.$offset); } else { $rs = $db->fetchAll('select * from '.$this->dbtable->getTable().$where.' order by '.$order.' limit '.$limit.' offset '.$offset); } return $rs; } /** * 獲得page.html * * @return string */ public function getResult(){ if ($this->pagesum == 0) { return false; } $smartyview = Zend_Registry::get('smartyview'); $smartyview->pageid = $this->pageid ; $smartyview->pages =$this->pages; $smartyview->prevpage=$this->prevpage; $smartyview->nextpage=$this->nextpage; $smartyview->pagebegin =$this->pagebegin; $smartyview->pageend =$this->pageend; $smartyview->pagesum = $this->pagesum; $smartyview->urlparam = $this->urlparam; return $smartyview->render('page.html'); } /** * 獲得<{$page}> * */ public function getPage(){ $smartyview = Zend_Registry::get('smartyview'); $smartyview->page=$this->getResult(); } }
view中的調用例子(smarty):
<div id="page" align="left"> <a href="<{$siteUrl}>/page/1<{$urlparam}>/username/<{$blogname}>">頭頁</a> <{if $pageid!=1}> <a href="<{$siteUrl}>/page/<{$prevpage}><{$urlparam}>/username/<{$blogname}>">上一頁</a> <{/if}> <{section loop=$pageend+1 name=loop start = $pagebegin }> <{if $smarty.section.loop.index == $pageid }> <a href="<{$siteUrl}>/page/<{$smarty.section.loop.index}><{$urlparam}>/username/<{$blogname}>" id ="pageid"><{$smarty.section.loop.index}></a> <{else}> <a href="<{$siteUrl}>/page/<{$smarty.section.loop.index}><{$urlparam}>/username/<{$blogname}>"><{$smarty.section.loop.index}></a> <{/if}> <{/section}> <{if $pageid != $pages}> <a href="<{$siteUrl}>/page/<{$nextpage}><{$urlparam}>/username/<{$blogname}>">下一頁</a> <{/if}> <a href="<{$siteUrl}>/page/<{$pages}><{$urlparam}>/username/<{$blogname}>">尾頁</a> <span>轉到</span> <select οnchange="window.location.href='<{$siteUrl}>/page/'+this.value+'<{$urlparam}>/username/<{$blogname}>'"> <{section loop=$pages+1 name=loop start = 1 }> <{if $smarty.section.loop.index == $pageid}> <option value="<{$smarty.section.loop.index}>" selected ><{$smarty.section.loop.index}></option> <{else}> <option value="<{$smarty.section.loop.index}>" ><{$smarty.section.loop.index}></option> <{/if}> <{/section}> </select> <span>頁</span> <span>共有數據<b> <{$pagesum}> </b>條,當前第<b> <{$pageid}> </b>頁,總共有<b> <{$pages}> </b>頁</span> </div>
前端面試題 - 說一下原型和原型鏈? JavaScript 中,萬物皆對象,對象分爲普通對象和函數對象。 所有的函數都是函數對象(typeof f === 'function'),其他都是普通對象(typeof o === 'object'
唯一索引(Unique Index):保證索引列的值是唯一的,即重複值不允許。 非唯一索引(Non-Unique Index):允許重複值存在。 組合索引(Composite Index):在表的多個列上創建索引。 反向鍵索引(Rever
一、簡單介紹: CaffeineCache和Guava的Cache是應用廣泛的本地緩存。 在開發中,爲了達到降低依賴、提高訪問速度的目的。會使用它存儲一些維表接口的返回值和數據庫查詢結果,在有些場景下也會在分佈式緩存上再加上一層本地緩存,
作者:vivo 互聯網大前端團隊 - Ma Lian 本文主要描述了FileProvider,startAnyWhere實現,Parcel不對稱漏洞以及這三者結合產生的漏洞利用實戰,另外闡述了漏洞利用的影響和修復預防措施,這個漏洞波及了
本文分享自華爲雲社區《GaussDB SQL基本語法示例-CASE表達式》,作者:Gauss松鼠會小助手2。 一、前言 SQL是用於訪問和處理數據庫的標準計算機語言。GaussDB支持SQL標準(默認支持SQL2、SQL3和SQL4的主要
Impala目前支持Hadoop中幾種常見的文件格式 Parquet 、 ORC 、 Text 、 Avro 、 RCFile 和 SequenceFile 。下面簡要說明各種格式的使用、限制和一些注意事項。 不同的文件格式有着不同的適用場
本文分享自華爲雲社區《GaussDB SQL基礎語法示例-BOOLEAN表達式》,作者:Gauss松鼠會小助手2。 一、前言 SQL是用於訪問和處理數據庫的標準計算機語言。GaussDB支持的SQL標準(默認支持SQL2、SQL3和SQL
Map是用於保存具有映射關係的數據集合,它具有雙列存儲的特點,即一次必須添加兩個元素,即一組鍵值對<Key,Value>,其中Key的值不可重複(當Key的值重複的時候,後面插入的對象會將之前插入的具有相同的Key值的對象覆蓋掉),Valu
前端面試題 - null是原始類型,但爲什麼typeof null的結果是object? 造成這個結果的原因是null的內存地址是以000開頭,而js會將000開頭的內存地址視爲object。 通過isNull()來判斷一個值是不是null
DHTMLX Suite UI 組件庫允許您更快地構建跨平臺、跨瀏覽器 Web 和移動應用程序。它包括一組豐富的即用式 HTML5 組件,這些組件可以輕鬆組合到單個應用程序界面中。 DHTMLX Gantt是用於跨瀏覽器和跨平臺應用程序的功
本文分享自華爲雲社區《GaussDB(DWS)向量化執行引擎詳解》,作者: yd_212508532。 前言 適用版本:【基線功能】 傳統的行執行引擎大多采用一次一元組的執行模式,這樣在執行過程中CPU大部分時間並沒有用來處理數據,更
SpringBoot如何優雅的進行參數校驗 一.爲什麼要進行參數校驗 在日常的開發過程中,我們常常需要對傳入的參數進行校驗,比如在web前後端分離項目中,參數校驗有兩個方面: 前端進行參數校驗 後端進行參數校驗 那這兩種
結構特點 List 和 Set 是存儲單列數據的集合,Map 是存儲鍵和值這樣的雙列數據的集合;List 中存儲的數據是有順序,並且允許重複;Map 中存儲的數據是沒有順序的,其鍵是不能重複的,它的值是可以有重複的,Set 中存儲的數據
Ai technology 前言 AppBuilder上線了低代碼製作組件功能,可以通過工作流的方式構建自定義組件,完成簡單Agent無法完成的複雜功能,使得生成的文本更加定製化,
最近在刷一些問題的時候看到有下面一個問題 上面問的是當輸入的字符串爲什麼的時候返回 True 總結 在做題目的時候,第一次還做錯了。 這是因爲解答這個題目的時間只有 3 分鐘,沒有自己看題目 後來拿着程序跑了下。 p