0712-2888027 189-8648-0214
微信公眾號(hào)

孝感風(fēng)信網(wǎng)絡(luò)科技有限公司微信公眾號(hào)

當(dāng)前位置:主頁(yè) > 技術(shù)支持 > PHPCMS > phpcms v9二次開(kāi)發(fā)所必須知道的步驟

phpcms v9二次開(kāi)發(fā)所必須知道的步驟

時(shí)間:2024-09-19來(lái)源:風(fēng)信官網(wǎng) 點(diǎn)擊: 943次

一、做phpcms-v9二次開(kāi)發(fā)時(shí),我們經(jīng)常需要用到如下代碼,所以有必須在這里注釋說(shuō)明一下

defined('IN_PHPCMS') or exit('No permission resources.');
//第一步:獲取模型緩存路徑
define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);

pc_base::load_app_func('util','content');
class index {
private $db;
function __construct() {
//第二步:獲取與數(shù)據(jù)庫(kù)相關(guān)的配置信息,如:數(shù)據(jù)表前綴、數(shù)據(jù)庫(kù)名、數(shù)據(jù)庫(kù)用戶(hù)名、數(shù)據(jù)庫(kù)密碼、數(shù)據(jù)庫(kù)編碼、數(shù)據(jù)庫(kù)類(lèi)型
$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');
}
//首頁(yè)
public function init() {
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');
include template('content','index',$default_style);
}
//內(nèi)容頁(yè)
public function show() {
$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');//獲取各欄目所對(duì)應(yīng)的站點(diǎn)id

$siteid = $siteids[$catid];//獲取當(dāng)前欄目所對(duì)應(yīng)的站點(diǎn)id

$CATEGORYS = getcache('category_content_'.$siteid,'commons');//獲取當(dāng)前站點(diǎn)下所有欄目的配置信息

if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) showmessage(L('information_does_not_exist'),'blank');

$this->category = $CAT = $CATEGORYS[$catid];//獲取當(dāng)前站點(diǎn)下當(dāng)前欄目的配置信息

$this->category_setting = $CAT['setting'] = string2array($this->category['setting']);

$siteid = $GLOBALS['siteid'] = $CAT['siteid'];//獲取當(dāng)前站點(diǎn)下當(dāng)前欄目所對(duì)應(yīng)的站點(diǎn)id值

$MODEL = getcache('model','commons');//獲取各個(gè)模型的配置信息

$modelid = $CAT['modelid'];//獲取當(dāng)前站點(diǎn)下當(dāng)前欄目所屬的模型id,找到了模型,也就找到了要查詢(xún)的模型表(數(shù)據(jù)表)

//設(shè)置模型表:通過(guò)緩存文件獲取modelid,然后再通過(guò)模型modelid獲取對(duì)應(yīng)的模型表及對(duì)應(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ù)庫(kù)為準(zhǔn)
$catid = $CATEGORYS[$r['catid']]['catid'];
$modelid = $CATEGORYS[$catid]['modelid'];

require_once CACHE_MODEL_PATH.'content_output.class.php';
$content_output = new content_output($modelid,$catid,$CATEGORYS);

//將查詢(xún)出來(lái)的數(shù)據(jù)經(jīng)模型處理函數(shù)處理后放入$data數(shù)據(jù)中
$data = $content_output->get($rs);

//注意:這行代碼非常之重要,主要用來(lái)將數(shù)組中各個(gè)元素轉(zhuǎn)化為變量,數(shù)據(jù)元素的鍵名為變量名,數(shù)據(jù)元素的值為變量值
extract($data);

熱門(mén)關(guān)鍵詞: phpcms 二次開(kāi)發(fā)
欄目列表
推薦內(nèi)容
熱點(diǎn)內(nèi)容
展開(kāi)