《CMS案例:phpcms v9把分類文件偽靜態目錄例子》要點:
本文介紹了CMS案例:phpcms v9把分類文件偽靜態目錄例子,希望對您有用。如果有疑問,可以聯系我們。
相關主題:PHPCMS教程
?CMS案例
- rewrite?^/([a-z]+)/$?/index.php?m=content&c=index&a=lists&catdir=$1?last;???
- rewrite?^/([a-z]+)/index_(\d+)\.html$?/index.php?m=content&c=index&a=lists&catdir=$1&page=$2?last;???
- rewrite?^/([a-z]+)/([a-z0-9-]+)\.html$?/index.php?m=content&c=index&a=show&catdir=$1&prefix=$2?last;???
- rewrite?^/([a-z]+)/([a-z0-9-]+)_(\d+)\.html$?/index.php?m=content&c=index&a=show&catdir=$1&prefix=$2&page=$3?last;???
這個Nginx規則就是把后面的鏈接重寫為前面的鏈接形式的.所以接下來需要做的就是讓后面的鏈接能夠訪問到正確的頁面.phpcms v9默認是無法訪問到正確頁面的,因為缺少必要的參數.下面就對phpcms v9進行修改.CMS案例
1、打開phpcms\modules\content目錄下的index.php找到 public function lists() {,將$catid = intval($_GET['catid']);替換成:
?CMS案例
- if(isset?($_GET['catid'])){???
- ???$catid?=?intval($_GET['catid']);???
- }else{???
- ???$catid=$this->_getCategoryId($_GET['catdir']);???
- }???
- ???
- //并且在最后的}?>?前添加:???
- ???
- private?function?_getCategoryId($catdir){???
- ????if(!strpos($catdir,'/'))?{???
- ????????$dirname?=?$catdir;???
- ????}else?{???
- ????????$dirname?=?end(explode('/',$catdir));???
- ????}//xiariboke.com???
- ????????$this->category_db?=?pc_base::load_model('category_model');???
- ????????$result?=?$this->category_db->get_one(array('catdir'=>$dirname));???
- ????return?$result['catid'];???
- ????}???
這段代碼的作用就是判斷參數是否catdir,欄目自定義目錄名,如果是目錄名則根據目錄名得到對應的catid,從而順利得到欄目頁.理解了自定義目錄的偽靜態方法之后,自定義文件名的偽靜態也就可以類似解決.CMS案例
2、打開phpcms\modules\content目錄下的index.php找到 public function show() {,
?CMS案例
- //將:???
- $catid?=?intval($_GET['catid']);???
- $id?=?intval($_GET['id']);???
- //替換成:???
- if(isset?($_GET['catid'])){???
- ????$catid?=?intval($_GET['catid']);???
- }else{???
- ????$catid=$this->_getCategoryId($_GET['catdir']);???
- }???
- if(isset($_GET['id'])){???
- ????$id?=?intval($_GET['id']);???
- }else{???
- ????$id?=?$this->_getPrefixId($_GET['catdir'],$_GET['prefix']);???
- }???
跟上面一樣,還需要加上判斷出文章id的函數,函數如下:
?CMS案例
- private?function?_getPrefixId($catdir,$prefix){???
- ????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));???
- ????$catid?=?$result['catid'];???
- ????$siteids?=?getcache('category_content','commons');???
- ????$siteid?=?$siteids[$catid];???
- ????$CATEGORYS?=?getcache('category_content_'.$siteid,'commons');???
- ????if(!isset($CATEGORYS[$catid])?||?$CATEGORYS[$catid]['type']!=0)?showmessage(L('information_does_not_exist'),'blank');???
- ????$this->category?=?$CAT?=?$CATEGORYS[$catid];???
- ????$this->category_setting?=?$CAT['setting']?=?string2array($this->category['setting']);???
- ????$siteid?=?$GLOBALS['siteid']?=?$CAT['siteid'];???
- ????$MODEL?=?getcache('model','commons');???
- ????$modelid?=?$CAT['modelid'];???
- ????$tablename?=?$this->db->table_name?=?$this->db->db_tablepre.$MODEL[$modelid]['tablename'];???
- ????$result?=?$this->db->get_one(array('prefix'=>$prefix));???
- ????if(emptyempty($result)){???
- ????????$result?=?$this->db->get_one(array('id'=>$prefix));???
- ????}???
- ????return?$result['id'];???
- }???
到這里之后,就可以通過自定義目錄加自定義文件名的形式訪問了.其他一些細節的地方,就不再贅述.CMS案例
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/5762.html