php はページャー CLinkPager インスタンスを書き換えます
1. カスタム ページャー クラスはどこに配置されますか?
配置する場所は 2 つあります。
2. 派生メソッドを使用するのが最善です
class MyPager extends CLinkPagerエントリ関数は次のとおりです: public function run()、ページャーが表示されるとき、run()呼び出し先、内部 出力は対応する位置に表示されます
<?php class MyPager extends CLinkPager { const CSS_FIRST_PAGE='first'; const CSS_LAST_PAGE='last'; const CSS_PREVIOUS_PAGE='previous'; const CSS_NEXT_PAGE='next'; const CSS_INTERNAL_PAGE='page'; const CSS_HIDDEN_PAGE='hidden'; const CSS_SELECTED_PAGE='selected'; /** * @var string the CSS class for the first page button. Defaults to 'first'. * @since 1.1.11 */ public $firstPageCssClass=self::CSS_FIRST_PAGE; /** * @var string the CSS class for the last page button. Defaults to 'last'. * @since 1.1.11 */ public $lastPageCssClass=self::CSS_LAST_PAGE; /** * @var string the CSS class for the previous page button. Defaults to 'previous'. * @since 1.1.11 */ public $previousPageCssClass=self::CSS_PREVIOUS_PAGE; /** * @var string the CSS class for the next page button. Defaults to 'next'. * @since 1.1.11 */ public $nextPageCssClass=self::CSS_NEXT_PAGE; /** * @var string the CSS class for the internal page buttons. Defaults to 'page'. * @since 1.1.11 */ public $internalPageCssClass=self::CSS_INTERNAL_PAGE; /** * @var string the CSS class for the hidden page buttons. Defaults to 'hidden'. * @since 1.1.11 */ public $hiddenPageCssClass=self::CSS_HIDDEN_PAGE; /** * @var string the CSS class for the selected page buttons. Defaults to 'selected'. * @since 1.1.11 */ public $selectedPageCssClass=self::CSS_SELECTED_PAGE; /** * @var integer maximum number of page buttons that can be displayed. Defaults to 10. */ public $maxButtonCount=10; /** * @var string the text label for the next page button. Defaults to 'Next >'. */ public $nextPageLabel; /** * @var string the text label for the previous page button. Defaults to '< Previous'. */ public $prevPageLabel; /** * @var string the text label for the first page button. Defaults to '<< First'. */ public $firstPageLabel; /** * @var string the text label for the last page button. Defaults to 'Last >>'. */ public $lastPageLabel; /** * @var string the text shown before page buttons. Defaults to 'Go to page: '. */ public $header; /** * @var string the text shown after page buttons. */ public $footer=''; /** * @var mixed the CSS file used for the widget. Defaults to null, meaning * using the default CSS file included together with the widget. * If false, no CSS file will be used. Otherwise, the specified CSS file * will be included when using this widget. */ public $cssFile; /** * @var array HTML attributes for the pager container tag. */ public $htmlOptions=array(); /** * Initializes the pager by setting some default property values. */ public function init() { if($this->nextPageLabel===null) $this->nextPageLabel=Yii::t('yii','Next >'); if($this->prevPageLabel===null) $this->prevPageLabel=Yii::t('yii','< Previous'); //if($this->firstPageLabel===null) // $this->firstPageLabel=Yii::t('yii','<< First'); //if($this->lastPageLabel===null) // $this->lastPageLabel=Yii::t('yii','Last >>'); if($this->header===null) $this->header=Yii::t('yii','Go to page: '); if(!isset($this->htmlOptions['id'])) $this->htmlOptions['id']=$this->getId(); if(!isset($this->htmlOptions['class'])) $this->htmlOptions['class']='yiiPager'; } /** * Executes the widget. * This overrides the parent implementation by displaying the generated page buttons. */ public function run() { $this->registerClientScript(); $buttons=$this->createPageButtons(); if(empty($buttons)) return; echo $this->header; // echo CHtml::tag('ul',$this->htmlOptions,implode("\n",$buttons)); echo implode("\n",$buttons); echo $this->footer; } /** * Creates the page buttons. * @return array a list of page buttons (in HTML code). */ protected function createPageButtons() { if(($pageCount=$this->getPageCount())<=1) return array(); list($beginPage,$endPage,$ellipsis)=$this->getPageRange(); $currentPage=$this->getCurrentPage(false); // currentPage is calculated in getPageRange() $buttons=array(); // first page //$buttons[]=$this->createPageButton($this->firstPageLabel,0,$this->firstPageCssClass,$currentPage<=0,false); // prev page if(($page=$currentPage-1)<0) $page=0; if($currentPage == 0){ $buttons[] = "<span style='background:#a3a3a3'><上一頁</span>"; }else{ $buttons[]=$this->createPageButton($this->prevPageLabel,$page,$this->previousPageCssClass,$currentPage<=0,false); } // internal pages start // first $buttons[]=$this->createPageButton(1,0,$this->internalPageCssClass,false,$i==$currentPage); //middle if($ellipsis == 'both'){ $buttons[] = "<span style='background:#a3a3a3'>...</span>"; } for($i=$beginPage;$i<=$endPage;++$i){ if($ellipsis == 'left' && $i == $beginPage){ $buttons[] = "<span style='background:#a3a3a3'>...</span>"; } $buttons[]=$this->createPageButton($i+1,$i,$this->internalPageCssClass,false,$i==$currentPage); if($ellipsis == 'right' && $i == $endPage){ $buttons[] = "<span style='background:#a3a3a3'>...</span>"; } } if($ellipsis == 'both'){ $buttons[] = "<span style='background:#a3a3a3'>...</span>"; } // last $buttons[]=$this->createPageButton($pageCount,$pageCount - 1,$this->internalPageCssClass,false,$i==$currentPage); // internal pages end // next page if(($page=$currentPage+1)>=$pageCount-1) $page=$pageCount-1; if($currentPage == ($pageCount-1)){ $buttons[] = "<span style='background:#a3a3a3'>下一頁></span>"; }else{ $buttons[]=$this->createPageButton($this->nextPageLabel,$page,$this->nextPageCssClass,$currentPage>=$pageCount-1,false); } // last page //$buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,$this->lastPageCssClass,$currentPage>=$pageCount-1,false); return $buttons; } /** * Creates a page button. * You may override this method to customize the page buttons. * @param string $label the text label for the button * @param integer $page the page number * @param string $class the CSS class for the page button. * @param boolean $hidden whether this page button is visible * @param boolean $selected whether this page button is selected * @return string the generated button */ protected function createPageButton($label,$page,$class,$hidden,$selected) { if($hidden || $selected) $class.=' '.($hidden ? $this->hiddenPageCssClass : $this->selectedPageCssClass); if ($selected) { $result = "<span>" . ++$page . "</span>"; } else { $result = CHtml::link($label,$this->createPageUrl($page)); } return $result; } /** * @return array the begin and end pages that need to be displayed. */ protected function getPageRange() { $currentPage=$this->getCurrentPage(); $pageCount=$this->getPageCount(); /*$beginPage=max(0, $currentPage-(int)($this->maxButtonCount/2)); if(($endPage=$beginPage+$this->maxButtonCount-1)>=$pageCount) { $endPage=$pageCount-1; $beginPage=max(0,$endPage-$this->maxButtonCount+1); }*/ if($pageCount > $this->maxButtonCount){ if($currentPage > 4 && $currentPage < ($pageCount - 4)){ // print_r('a'); $beginPage = $currentPage - 2; $endPage = $currentPage + 2; $ellipsis = 'both'; }else{ $beginPage=max(1, $currentPage-(int)($this->maxButtonCount/2)); if($beginPage == 1){ $ellipsis = 'right'; }else{ $ellipsis = 'left'; } if(($endPage=$beginPage+$this->maxButtonCount-1)>=$pageCount) { // print_r('b'); $endPage=$pageCount-2; $beginPage=max(1,$endPage-$this->maxButtonCount+1); }elseif(($endPage=$beginPage+$this->maxButtonCount-1)>=$pageCount-2){ // print_r('c'); $endPage=$pageCount-2; } } }else{ $beginPage=max(1, $currentPage-(int)($this->maxButtonCount/2)); if(($endPage=$beginPage+$this->maxButtonCount-1)>=$pageCount) { $endPage=$pageCount-2; $beginPage=max(1,$endPage-$this->maxButtonCount+1); } } return array($beginPage,$endPage, $ellipsis); } /** * Registers the needed client scripts (mainly CSS file). */ public function registerClientScript() { if($this->cssFile!==false) self::registerCssFile($this->cssFile); } /** * Registers the needed CSS file. * @param string $url the CSS URL. If null, a default CSS URL will be used. */ public static function registerCssFile($url=null) { if($url===null) $url=CHtml::asset(Yii::getPathOfAlias('system.web.widgets.pagers.pager').'.css'); Yii::app()->getClientScript()->registerCssFile($url); } }
3) を参照してください。 View の対応するウィジェットで、ページャー クラスを次のように定義します。カスタム ページャー クラス名、参照: $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view_t',
'pager'=>array(
'class'=>'MyPager',
)
));
以上がPHP 書き換えページャー CLinkPager のサンプル コード共有の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

データベースストレージセッションを使用することの主な利点には、持続性、スケーラビリティ、セキュリティが含まれます。 1。永続性:サーバーが再起動しても、セッションデータは変更されないままになります。 2。スケーラビリティ:分散システムに適用され、セッションデータが複数のサーバー間で同期されるようにします。 3。セキュリティ:データベースは、機密情報を保護するための暗号化されたストレージを提供します。

PHPでのカスタムセッション処理の実装は、SessionHandlerInterfaceインターフェイスを実装することで実行できます。具体的な手順には、次のものが含まれます。1)CussentsessionHandlerなどのSessionHandlerInterfaceを実装するクラスの作成。 2)セッションデータのライフサイクルとストレージ方法を定義するためのインターフェイス(オープン、クローズ、読み取り、書き込み、破壊、GCなど)の書き換え方法。 3)PHPスクリプトでカスタムセッションプロセッサを登録し、セッションを開始します。これにより、データをMySQLやRedisなどのメディアに保存して、パフォーマンス、セキュリティ、スケーラビリティを改善できます。

SessionIDは、ユーザーセッションのステータスを追跡するためにWebアプリケーションで使用されるメカニズムです。 1.ユーザーとサーバー間の複数のインタラクション中にユーザーのID情報を維持するために使用されるランダムに生成された文字列です。 2。サーバーは、ユーザーの複数のリクエストでこれらの要求を識別および関連付けるのに役立つCookieまたはURLパラメーターを介してクライアントに生成および送信します。 3.生成は通常、ランダムアルゴリズムを使用して、一意性と予測不可能性を確保します。 4.実際の開発では、Redisなどのメモリ内データベースを使用してセッションデータを保存してパフォーマンスとセキュリティを改善できます。

APIなどのステートレス環境でのセッションの管理は、JWTまたはCookieを使用して達成できます。 1。JWTは、無国籍とスケーラビリティに適していますが、ビッグデータに関してはサイズが大きいです。 2.cookiesはより伝統的で実装が簡単ですが、セキュリティを確保するために慎重に構成する必要があります。

セッション関連のXSS攻撃からアプリケーションを保護するには、次の測定が必要です。1。セッションCookieを保護するためにHTTPonlyとセキュアフラグを設定します。 2。すべてのユーザー入力のエクスポートコード。 3.コンテンツセキュリティポリシー(CSP)を実装して、スクリプトソースを制限します。これらのポリシーを通じて、セッション関連のXSS攻撃を効果的に保護し、ユーザーデータを確保できます。

PHPセッションのパフォーマンスを最適化する方法は次のとおりです。1。遅延セッション開始、2。データベースを使用してセッションを保存します。これらの戦略は、高い並行性環境でのアプリケーションの効率を大幅に改善できます。

thesession.gc_maxlifettinginttinginphpdethinesthelifsessessiondata、setinseconds.1)it'sconfiguredinphp.iniorviaini_set()。 2)AbalanceSneededToAvoidPerformanceIssues andunexpectedLogouts.3)php'sgarbagecollectionisisprobabilistic、影響を受けたBygc_probabi

PHPでは、session_name()関数を使用してセッション名を構成できます。特定の手順は次のとおりです。1。session_name()関数を使用して、session_name( "my_session")などのセッション名を設定します。 2。セッション名を設定した後、session_start()を呼び出してセッションを開始します。セッション名の構成は、複数のアプリケーション間のセッションデータの競合を回避し、セキュリティを強化することができますが、セッション名の一意性、セキュリティ、長さ、設定タイミングに注意してください。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

mPDF
mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

メモ帳++7.3.1
使いやすく無料のコードエディター

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境
