//第一步:獲取模型緩存路徑
define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR); pc_base::load_app_func('util','content'); classindex { private$db; function__construct() {
//第二步:獲取與數(shù)據(jù)庫相關(guān)的配置信息,如:數(shù)據(jù)表前綴、數(shù)據(jù)庫名、數(shù)據(jù)庫用戶名、數(shù)據(jù)庫密碼、數(shù)據(jù)庫編碼、數(shù)據(jù)庫類型 $this->db = pc_base::load_model('content_model'); $this->_userid = param::get_cookie('_userid'); $this->_username = param::get_cookie('_username'); $this->_groupid = param::get_cookie('_groupid'); }
//首頁
publicfunctioninit() { if(isset($_GET['siteid'])) { $siteid= intval($_GET['siteid']); } else{ $siteid= 1;//模型情況下siteid為1 } $siteid= $GLOBALS['siteid'] = max($siteid,1); define('SITEID', $siteid); $_userid= $this->_userid; $_username= $this->_username; $_groupid= $this->_groupid; //SEO $SEO= seo($siteid); $sitelist= getcache('sitelist','commons'); $default_style= $sitelist[$siteid]['default_style']; $CATEGORYS= getcache('category_content_'.$siteid,'commons'); includetemplate('content','index',$default_style); }
//內(nèi)容頁
publicfunctionshow() { $catid= intval($_GET['catid']); $id= intval($_GET['id']); if(!$catid|| !$id) showmessage(L('information_does_not_exist'),'blank'); $_userid= $this->_userid; $_username= $this->_username; $_groupid= $this->_groupid; $page= intval($_GET['page']); $page= max($page,1); $siteids= getcache('category_content','commons');//獲取各欄目所對應(yīng)的站點id $siteid= $siteids[$catid];//獲取當(dāng)前欄目所對應(yīng)的站點id $CATEGORYS= getcache('category_content_'.$siteid,'commons');//獲取當(dāng)前站點下所有欄目的配置信息 if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) showmessage(L('information_does_not_exist'),'blank'); $this->category = $CAT= $CATEGORYS[$catid];//獲取當(dāng)前站點下當(dāng)前欄目的配置信息 $this->category_setting = $CAT['setting'] = string2array($this->category['setting']); $siteid= $GLOBALS['siteid'] = $CAT['siteid'];//獲取當(dāng)前站點下當(dāng)前欄目所對應(yīng)的站點id值 $MODEL= getcache('model','commons');//獲取各個模型的配置信息 $modelid= $CAT['modelid'];//獲取當(dāng)前站點下當(dāng)前欄目所屬的模型id,找到了模型,也就找到了要查詢的模型表(數(shù)據(jù)表) //設(shè)置模型表:通過緩存文件獲取modelid,然后再通過模型modelid獲取對應(yīng)的模型表及對應(yīng)的模型附表 $tablename= $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];
//設(shè)置模型附表
$r= $this->db->get_one(array('id'=>$id)); if(!$r|| $r['status'] != 99) showmessage(L('info_does_not_exists'),'blank'); //下面代碼獲取的是當(dāng)前模型附表中數(shù)據(jù) $this->db->table_name = $tablename.'_data'; //下面代碼獲取的是當(dāng)前模型附表中數(shù)據(jù) $r2= $this->db->get_one(array('id'=>$id)); //將模型表數(shù)據(jù)和模型附表中數(shù)據(jù)合并在一起 $rs= $r2? array_merge($r,$r2) : $r; //再次重新賦值,以數(shù)據(jù)庫為準(zhǔn) $catid= $CATEGORYS[$r['catid']]['catid']; $modelid= $CATEGORYS[$catid]['modelid']; require_onceCACHE_MODEL_PATH.'content_output.class.php'; $content_output= newcontent_output($modelid,$catid,$CATEGORYS); //將查詢出來的數(shù)據(jù)經(jīng)模型處理函數(shù)處理后放入$data數(shù)據(jù)中 $data= $content_output->get($rs); //注意:這行代碼非常之重要,主要用來將數(shù)組中各個元素轉(zhuǎn)化為變量,數(shù)據(jù)元素的鍵名為變量名,數(shù)據(jù)元素的值為變量值 extract($data);
版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除!謝謝!
轉(zhuǎn)載請注明: phpcmsv9二次開發(fā)方法