Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The YII CLinkPager paging class extension increases how many pages are displayed

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "how to display a total number of pages in YII CLinkPager paging class extension". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. The effect of default CLinkPager display

The style of css is written here. Let's take a look at the pager code:

2. Let's look at the desired paging effect.

In other words, the following addition shows a total of how many pages, how to do this? Here I slightly extend the widget component CLinkPager, it also looks very simple, not much nonsense, let's take a look at the code:

* * when / class MLinkPager extends CLinkPager {/ / is set to true, a total of X pages are displayed. The value of $this- > forceTotalPage gives priority to the value public $mCountPage = false;//. If set to true, $this- > mCountPage and $this- > getPageRange () are invalid public $forceTotalPage = false;public function init () {} public function run () {$this- > registerClientScript (); $buttons=$this- > createPageButtons (); list ($beginPage,$endPage) = $this- > getPageRange () If ($this- > forceTotalPage) {$buttons [] = CHtml::tag ('li', array (' class'= > 'totle'),' total'. $this- > getPageCount (). Page');} else {if ($this- > mCountPage & & $endPage > 0) {$buttons [] = CHtml::tag ('li', array (' class'= > 'totle'),' total'. $this- > getPageCount (). Page');} if (empty ($buttons)) return;echo $this- > header;echo CHtml::tag ('div',$this- > htmlOptions,implode ("\ n", $buttons)); echo $this- > footer;}}

Someone said, how can you see the effect as quickly as possible when you look at such a pile of code and have a headache? Let's continue to see how to use it. First of all, you need to copy the above extension MLinkPager intact to the MlinkPager file in the local components directory. What, you don't have this file, create it yourself, ^ ~ ^! All right, let's take a look at how view is used in the future. It's simple and can't be too simple.

What? You just woke up with a bad look in your eyes, didn't you see the difference? Pay attention to the configuration item mCountPage of MLinkPager, this setting is true and everything will be fine!

Special note: if your list does not have data, paging does not show the page number, but if there is a demand for unruly products, there is no list data, but you have to show a total of 0 pages. Our MlinkPager only needs to set the configuration item forceTotalPage to true. Setting mCountPager is invalid at this time. For details, please see the MlinkPage class, and the subclass can be expanded by yourself.

Here's how to use paging in yii.

It is convenient to use paging in yii. There are two methods:

In the controller:

1 、

$criteria = new CDbCriteria (); / / new cdbcriteria database

$criteria- > id ='id ASC'; / / collation $count = Exchange::model ()-> count ($criteria); $pager = new CPagination ($count); $pager- > pageSize=30;$pager- > applyLimit ($criteria); $categoryInfo = Category::model ()-> findAll ($criteria); / / query by condition

2 、

$criteria = new CDbCriteria (); $criteria- > order ='id ASC';$criteria- > addCondition ('status=1'); / / query $criteria- > addCondition (' exchange_status=0') based on conditions; $count = Exchange::model ()-> count ($criteria); $pager = new CPagination ($count); $pager- > pageSize=30;$pager- > applyLimit ($criteria); $exchangeInfo = Exchange::model ()-> findAll ($criteria)

Parameters passed in render:

Array ("pages" = > $pager)

Add to the view:

$this- > widget ('CLinkPager',array (' header'= >', 'firstPageLabel' = >' home page', 'lastPageLabel' = >' last page', 'prevPageLabel' = >' previous page', 'nextPageLabel' = >' next page', 'pages' = > $pages,'maxButtonCount'= > 8,))

Paging ideas:

1. Calculate the total number of entries in the database

2. Page size

3. Set offset limit

In Yii, it is important to use this class CDBcritria to query the database when paging, so paging is simple.

This is the end of the content of "how to display the total number of pages added to the YII CLinkPager paging class extension". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report