添加页插件类:
/** * 分页 * */ 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>
這個其實是一個特別高頻的面試題,松哥也一直很想和大家仔細來聊一聊這個話題,網上關於這塊的文章很多,但是我一直覺得要把這個問題講清楚還有點難度,今天我來試一試,看能不能和小夥伴們把這個問題梳理清楚,當然,如果小夥伴們覺得看文章不過癮,松哥也有
分享8個開箱即用的API,方便日常處理集合。 1. 快速過濾空值:Stream.ofNullable 該方法是在 Java 9 中引入的,有助於過濾集合中的所有空值,從而可能使我們避免空指針異常。 在下面的示例中,有一個包含 null 的L
一、背景 在日常部門OpsReview過程中,部門內多次遇到應用容器所在的宿主機磁盤繁忙導致的接口響應緩慢,TP99增高等影響服務性能的問題,其中比較有效的解決方案是開啓日誌的異步打印,可以有效避免同步日誌打印在磁盤IO高起的情況下拖慢業
本文分享自華爲雲社區《【MySQL技術專欄】MySQL8.0直方圖介紹》,作者:GaussDB 數據庫。 背景 數據庫查詢優化器負責將SQL查詢轉換爲儘可能高效的執行計劃,但因爲數據環境不斷變化導致優化器對查詢數據瞭解的不夠充足,可能無法
每篇一句 大魔王張怡寧:女兒,這堆金牌你拿去玩吧,但我的銀牌不能給你玩。你要想玩銀牌就去找你王浩叔叔吧,他那銀牌多 前言 爲了講述好Spring MVC最爲複雜的數據綁定這塊,我前面可謂是做足了功課,對此部分知識此處給小夥伴留一個學
作者:vivo 互聯網數據庫團隊- Qiu Xinbo 本文主要通過圖示介紹了用主鍵進行分片查詢的過程,介紹了主鍵分頁查詢存在SQL性能問題,如何去創建高效的索引去優化主鍵分頁查詢的SQL性能問題 對於數據分佈不均
JSON簡介: JSON(Java Script Object Notation)是一種輕量級的數據交換格式,通常用於在不同系統之間傳輸數據。它基於 JavaScript 對象語法,但已成爲一種獨立於語言的格式。JSON 數據以鍵值對的形式
一、簡單介紹: 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
本文分享自華爲雲社區《10分鐘搞懂各種內存溢出案例!!(含完整源碼,建議收藏)》,作者:冰 河。 作爲程序員,多多少少都會遇到一些內存溢出的場景,如果你還沒遇到,說明你工作的年限可能比較短,或者你根本就是個假程序員!哈哈,開個玩笑。今天,我
Ai technology 前言 AppBuilder上線了低代碼製作組件功能,可以通過工作流的方式構建自定義組件,完成簡單Agent無法完成的複雜功能,使得生成的文本更加定製化,
最近在刷一些問題的時候看到有下面一個問題 上面問的是當輸入的字符串爲什麼的時候返回 True 總結 在做題目的時候,第一次還做錯了。 這是因爲解答這個題目的時間只有 3 分鐘,沒有自己看題目 後來拿着程序跑了下。 p