BluePage generic paging helps developers improve development efficiency

Source: Internet
Author: User
BluePage generic paging helps developers improve development efficiency. reading BluePage generic paging helps developers improve development efficiency. paging is a common function for websites. if there is a good paging class (function ), it can help developers save a lot of development time. 1 Page is independent of SQL. Why does paging have nothing to do with SQL? Obviously, Peng "> <LINKhref =" http: // www  

Paging is a common function of websites. if there is a good paging class (function), it can help developers save a lot of development time.

1 Page is independent of SQL. Why does paging have nothing to do with SQL? Obviously, some friends with certain development experience are at least using the database proxy class. We should not pass the global interface or the database class in the paging class. as for directly putting the database connection in, we should not. In addition, please refer to the 5th points.

2 pages must be separated from html and styles. Separation from html is an obvious requirement. first, even a website requires pages of different styles, or even images. Second, you can handle different encoding formats. In addition, the separation from html and style is equivalent to the template technology of PHP. the artist can modify the desired effect.

3. variable values should be considered. not all pages are numerical. For example, some people use page = pn123, or even page = p123nfadfafdaf. The paging class must provide processing in this respect.

4. the web protocol is not limited to http. In many paging classes, the protocol is fixed to http, which is not desirable.

Only the four most basic points above can be seen in the so-called paging class, but there are basically no two of them.

Okay. Let's start.

5 pages are not limited to database pages. Some pages are for the content, such as paging a piece of content that is up to ten thousand characters long. in this way, if you write SQL into the class, it will be even worse, and it will not be used at all.

BluePage is a common paging class that helps you complete paging tasks faster.

First look at the example: http://www.bluessoft.com/project/bluepage/example.php

Example 1:

        
         Get ($ intCount, $ intShowNum); $ strHtml = $ pBP-> getHTML ($ aPDatas); // output or assign a value to a template variable at an appropriate position?>
        

:

Example 2:

        
         Get ($ intCount, $ intShowNum); // print_r ($ aPDatas); // Print it out if you do not remember to return it.
        

Example 3:

        
         Get ($ intCount, $ intShowNum); // The second parameter specifies the configuration file $ strHtml = $ pBP-> getHTML ($ aPDatas, "myBPDiy. inc. php");?>
        

Output Control:

        
         Get ($ intCount, $ intShowNum ); // f homepage // page number of the previous group of pg // p previous page // bar page number/ng next group of pages // n next page/m Total Page number // sl drop-down list page // I Input form $ pBP-> _ order ='m | sl '; // only output the total page number and drop-down page $ strHtml = $ pBP-> getHTML ($ aPDatas);?>
        

Example 5

        
         _ Getlink = false; // cancel obtaining the link $ pBP-> _ getqs = false; // cancel obtaining the Query String // return the paging number (saving resources) $ aPDatas = $ pBP-> get ($ intCount, $ intShowNum); // print_r ($ aPDatas); // Print it out to see it. // as long as the maximum page is displayed, the previous page is displayed, returns with the next page and current page, and offset (the least resource) $ aPDatas = $ pBP-> get ($ intCount, $ intShowNum, 0); // print_r ($ aPDatas ); // print it and see it?>
        

Get offset

        
         Get ($ intCount, $ intShowNum); $ offset = $ aPDatas ['offset'];?>
        

Non-database paging:

For example, if the length of an article is 10000 bytes and every 2000 bytes is divided into one page, what should we do?

        
         Get ($ strLen, $ strSubLen); $ offset = $ aPDatas ["offset"]; // get the content of the current page $ strSubContent = fn_substr ($ strSubContent, $ offset, $ strSubLen); // write the screenshot function by yourself?>
        

Some attributes:

8.1 The variables you use are not pages, but others, such as pn:

        
         _var = 'pn' ;$aPDatas = $pBP->get( $intCount, $intShowNum );?>
        

8.2 $ this-> _ prefix?

        
         
When a number such as page = pp123 is preceded by a character, $ this-> _ prefix is useful.
         _ Prefix = 'pp '; // for example, page = pp of pp123 $ aPDatas = $ pBP-> get ($ intCount, $ intShowNum);?>
        

8.3 $ this-> _ What is the role of postfix? :

$ This-> _ postfix is useful when a number like page = 123p is followed by a character.

        
         _ Postfix = 'p'; // for example, page = 123p p $ aPDatas = $ pBP-> get ($ intCount, $ intShowNum);?>
        

8.4 $ this-> _ prefix and $ this-> _ postfix can be used simultaneously? :

Of course. When a number similar to page = pn123ccc is followed by a character

        
         _prefix = 'pn' ; $pBP->_postfix = 'ccc' ; $aPDatas = $pBP->get( $intCount, $intShowNum );?>
        

8.5 $ this-> _ What is the use of pos? :

It is used to set the position of the current page in the paging bar. for example, if it is set to 3 and the current page is 8, the number 8 is placed in the third position of the paging bar: 6 7 8 9 10 11 12 13 14 15

        
         _ Pos = 5; // place the current page to the fifth place $ aPDatas = $ pBP-> get ($ intCount, $ intShowNum);?>
        

8.6 $ this-> _ symbol? :

Connector

        
         _ Symbol = '&'; // Use & as the link $ aPDatas = $ pBP-> get ($ intCount, $ intShowNum);?>
        

8.7 $ this-> _ getqs? :

Whether to obtain the Query String. It is obtained by default. if it is false, it is not obtained. It can save resources, but if you want to obtain the link and html, it will be true

        
         _getqs = false ; $aPDatas = $pBP->get( $intCount, $intShowNum );?>
        

8.8 $ this-> _ getlink? :

This-> _ getlink is set to true by default, indicating that the paging link is obtained. if it is set to false, no variable related to * ln key name has a value, 1 applies to people who manually set Links 2 saves resources

        
         _getlink = false ;$aPDatas = $pBP->get( $intCount, $intShowNum );?>
        

8.9 $ this-> _ encode? :

$ This-> _ encode: The default value is true, indicating that the Query String is filtered using htmlspecialchars.

        
         _ Encode = false; // do not filter query string $ aPDatas = $ pBP-> get ($ intCount, $ intShowNum);?>
        

Finally:

About the configuration file BluePage. default. inc. php

This is the default configuration file. You can copy the content and save it as another configuration. For example, name it page. abc. inc. php assumes that the current access is list. php file, in list. the php directory at the same level has a directory to save the config, such. /config directory, and you set page. abc. inc. php is saved in. /config directory.

        
         _ Encode = false; // do not filter query string $ aPDatas = $ pBP-> get ($ intCount, $ intShowNum); $ strHtml = $ pBP-> getHTML ($ aPDatas, '. /config/page. abc. inc. php '); // is the path correct?>
        

Save the encoding format based on your page output code. Just like a template.

If your page is in UTF-8 format, save the configuration file in UTF-8 format. Note: You only need to change the page. abc. inc. php encoding. do not change the encoding of class files.

Add:

If you do not find it inconvenient to retrieve the total number of records, you can add a function to the class or use an external function.

In practical applications, the method for getting the number of records follows the project object, so it is generally not added to the paging class.

If you do not have the method to retrieve the number of records, you can add them to the paging class or to the external

[Php]

Program example:

        
         MyGetCount ($ strQuery, $ dbconn); // The number of records obtained. // for SQLserver $ intCount = $ pBP-> msGetCount ($ strQuery, $ dbconn ); // get the number of records $ pBP-> get ($ intCount, 10); // Retrieve paging data?>
        

Of course, we do not encourage you to add database operations to the paging class.

[/Php]

Home: http://www.bluessoft.com/project/bluepage/

: Http://www.bluessoft.com/project/bluepage/BluePage.tar.gz

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.