本人做過多次PHPCMS二次開發,現在基本上開發起來感覺都比較靈活,所以做些筆記,不感說做的好,但也記錄下一些解決辦法,開發經驗,希望能幫助到用的到的人。
各位有什麼意見可以指點一二。
一、關於 新聞 型信息對新添加字段值的插入。
當你從後臺模型中去添加新字段,而且用的也是系統提供的類型,這自然可以正常的插入值。但當系統中的類型不能支持你的需求,需要自己定義顯示方式輸入值時,你不得不去添加一個並非你要顯示出現的類型,所以你需要在頁面中手工來寫輸入方式,或者說字段是直接通過數據庫添加的,(當然如果完全按照PHPCMS系統來再做新字段類型的輸入也可以,但這樣太麻煩了,對於開發的工期來講,我們往往沒有那麼多的時間),那這樣這裏的字段的值就無法插入到數據表中,因爲系統中用了模型來做插入,我們的字段是非正常添加的,所以模型關聯的字段中不包括我們新添加的字段,所以不能插入。解決辦法是:在插入的程序之前我們把新加的字段值加到要插入的數組中。
///插入模型表 文件:admin/content.class.php 中的add方法中。
$modelinfo['infokind']=$data['infokind'];
$modelinfo['infokindother']=$data['infokindother'];
//以上是新添加的兩個字段。
$this->db->insert($this->model_table, $modelinfo);
二、開發中常用代碼
開發說明:
system_info.php
導入SYSTEM_INFO.PHP:require_once PHPCMS_ROOT.'include/system_info.php';
global.func.php
導入GLOBAL:require_once MOD_ROOT.'include/global.func.php';
分頁:
$page = max(intval($page), 1);
$pagesize = 10;
$offset = $pagesize*($page-1);
$limit = "LIMIT $offset, $pagesize";
$data=$db->select("select * from cms_yp_category where kind=$kind order by orderid $limit");
$datas=$db->get_one("select count(*) as num from cms_yp_category where kind=$kind");
$pages = pages(datas['num'], $page, $pagesize);
欄目名稱:=$CATEGORY[$catid]['catname'];
新聞推薦調用:
{get sql="select * from hr_content where catid=34 and status=99 and contentid in(select contentid from hr_content_position where posid=1) order by listorder,inputtime desc limit 0,9"}
<li><span><a href="{$r[url]}">{str_cut($r[title],64)}</a></span><font>{date('Y-m-d',$r[inputtime])}</font></li>
{/get}
內部模塊圖片:
{get sql="select * from hr_c_picads p,hr_content c where p.contentid=c.contentid and contentid=118"}
<a href="{$r[linkurl]}"><img src="{$r[thumb]}" width="241" height="141" /></a>
{/get}