PHPCMS V9 custom column pseudo-static implementation method (list page/content page)

Source: Internet
Author: User
Tags explode

First, let's take a look at the urlrewrite rules. This is in Apache, and the rules in other environments are switched by themselves.

RewriteEngine on
# Static files and API directories do not require pseudo-static files
RewriteRule ^ (statics | api | uploadfile) (. *)-[L]

# Content page
RewriteRule ^ ([0-9A-Za-z _/] *)/([0-9] +) \. html index. php? M = content & c = index & a = show & dir = $1 & id = $2
RewriteRule ^ ([0-9A-Za-z _/] *)/([0-9] +) _ ([0-9] +) \. html index. php? M = content & c = index & a = show & dir = $1 & id = $2 & page = $3

# Topic Page
RewriteRule ^ ([0-9A-Za-z _/] *)/index _ ([1-9] [0-9] *) \. html index. php? M = content & c = index & a = lists & dir = $1 & page = $2
RewriteRule ^ ([0-9A-Za-z _/] *)/index. php? M = content & c = index & a = lists & dir = $1
1. Open index. php in the final directory of phpcms \ modules \ content.}?> Add:


/*** Obtain the ID based on the column name * @ param $ catdir */
Function _ getCategoryId ($ catdir ){
$ This-> category_db = pc_base: load_model ('Category _ Model ');
$ Result = $ this-> category_db-> select (array ('catdir' => $ catdir ));
// Print_r ($ result );
Return $ result;
         }
First, add a method to convert 'catdir' to 'catid'
This was modified by referring to the document of the webmaster's house. In this case, I have been struggling to directly read the cache or query the database. To read the cache, I need to traverse the array, i'm afraid the efficiency is not so high if there are too many columns. It is added to the front of the // homepage.

Private function _ getCategoryId ($ catdir ){
If (! Strpos ($ catdir ,'/')){
$ Dirname = $ catdir;
} Else {
$ Dirname = end (explode ('/', $ catdir ));
                }
$ This-> category_db = pc_base: load_model ('Category _ Model ');
$ Result = $ this-> category_db-> get_one (array ('catdir' => $ dirname ));
Return $ result ['catid'];
        }
In the 'show () 'method, modify the 'catid' statement.

$ Catid = intval ($ _ GET ['catid']
Replace

// $ Catid = intval ($ _ GET ['catid']);
If (isset ($ _ GET ['catid']) {
$ Catid = intval ($ _ GET ['catid']);
} Else {
$ Catid = $ this-> _ getCategoryId ($ _ GET ['dir']);
                }
Modify the 'catid' statement in the lists () method.

$ Catid = $ _ GET ['catid'] = intval ($ _ GET ['catid']);
Replace

// $ Catid = intval ($ _ GET ['catid']);
If (isset ($ _ GET ['catid']) {
$ Catid = intval ($ _ GET ['catid']);
} Else {
$ Catid = $ this-> _ getCategoryId ($ _ GET ['dir']);
                }
Then, add two custom URL rules in the phpcms background.
URL rule topic page: {$ categorydir }{$ catdir}/| {$ categorydir }{$ catdir}/index_?#page=.html
URL rule content page: {$ categorydir }{$ catdir}/{$id1_.html | {$ categorydir }{$ catdir}/{$id1__{$page1_.html

Find

$ GLOBALS ['url _ array'] ['categorydir'] = $ categorydir;
$ GLOBALS ['url _ array'] ['catdir'] = $ catdir;
$ GLOBALS ['url _ array'] ['catid'] = $ catid;
Replace

$ GLOBALS ['url _ array'] ['categorydir'] = $ parentdir;
$ GLOBALS ['url _ array'] ['catdir'] = $ catdir;
$ GLOBALS ['url _ array'] ['catid'] = $ catid;
2. Open url. class. php in the phpcms \ modules \ content \ classes directory and find

If (! $ Setting ['ishtml ']) {// If static
Set the following:

$ Url = str_replace (array ('{$ catid}', '{$ page}'), array ($ catid, $ page), $ urlrule );
If (strpos ($ urls ,'\\')! = False ){
$ Url = APP_PATH.str_replace ('\', '/', $ urls );
            }
Replace:

 
$ Domain_dir = '';
If (strpos ($ category ['URL'], ': //')! = False & strpos ($ category ['URL'], '? ') = False ){
If (preg_match ('/^ (http | https ):\/\/)? ([^ \/] +)/I ', $ category ['URL'], $ matches )){
$ Match_url = $ matches [0];
$ Url = $ match_url .'/';
                }  
$ Db = pc_base: load_model ('Category _ Model ');
$ R = $ db-> get_one (array ('URL' => $ url), ''catid '');
 
If ($ r) $ domain_dir = $ this-> get_categorydir ($ r ['catid']). $ this-> categorys [$ r ['catid'] ['catdir']. '/';
            }  
$ Categorydir = $ this-> get_categorydir ($ catid );
$ Catdir = $ category ['catdir'];
$ Year = date ('Y', $ time );
$ Month = date ('M', $ time );
$ Day = date ('D', $ time );
// Echo $ catdir;
$ Urls = str_replace (array ('{$ categorydir}', '{$ catdir}', '{$ year}', '{$ month }', '{$ day}', '{$ catid}', '{$ id}', '{$ prefix}', '{$ page }'), array ($ categorydir, $ catdir, $ year, $ month, $ day, $ catid, $ id, $ prefix, $ page), $ urlrule );
// Echo $ urls. "<br/> ";
If (strpos ($ urls ,'\\')! = False ){
$ Urls = APP_PATH.str_replace ('\', '/', $ urls );
            }  
$ Url = $ domain_dir. $ urls;
3. Paging troubleshooting \ phpcms \ libs \ functions \ global. func. php

/**
* Return paging path
 *
* @ Param $ urlrule paging rule
* @ Param $ page current page
* @ Param $ array the array to be passed, used to add additional methods
* @ Return complete URL path
*/
 
Function pageurl ($ urlrule, $ page, $ array = array ()){
If (strpos ($ urlrule ,'~ ')){
$ Urlrules = explode ('~ ', $ Urlrule );
$ Urlrule = $ page <2? $ Urlrules [0]: $ urlrules [1];
    }
$ Findimethyl = array ('{$ page }');
$ Replaceme = array ($ page );
If (is_array ($ array) foreach ($ array as $ k => $ v ){
$ Findimethyl [] = '{$'. $ k .'}';
$ Replaceme [] = $ v;
 
    }
 
$ Url = str_replace ($ findimethyl, $ replaceme, $ urlrule );
$ Url = str_replace (array ('http ://','//','~ '), Array ('~ ','/', 'Http: //'), $ url );
If (! Strstr ($ url, siteurl (get_siteid ()))){
$ Url = siteurl (get_siteid (). '/'. $ url;
        }
Return $ url;
 
}
Then update the column cache and update URLs in batches to see the effect.

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.