0712-2888027 189-8648-0214
微信公眾號

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

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

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

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

一、做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() {
//第二步:獲取與數據庫相關(guān)的配置信息,如:數據表前綴、數據庫名、數據庫用戶(hù)名、數據庫密碼、數據庫編碼、數據庫類(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);
}
//內容頁(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');//獲取各欄目所對應的站點(diǎn)id

$siteid = $siteids[$catid];//獲取當前欄目所對應的站點(diǎn)id

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

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

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

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

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

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

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

//設置模型表:通過(guò)緩存文件獲取modelid,然后再通過(guò)模型modelid獲取對應的模型表及對應的模型附表
$tablename = $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];

//設置模型附表
$r = $this->db->get_one(array('id'=>$id));

if(!$r || $r['status'] != 99) showmessage(L('info_does_not_exists'),'blank');

//下面代碼獲取的是當前模型附表中數據
$this->db->table_name = $tablename.'_data';

//下面代碼獲取的是當前模型附表中數據
$r2 = $this->db->get_one(array('id'=>$id));

//將模型表數據和模型附表中數據合并在一起
$rs = $r2 ? array_merge($r,$r2) : $r;

//再次重新賦值,以數據庫為準
$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)的數據經(jīng)模型處理函數處理后放入$data數據中
$data = $content_output->get($rs);

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

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