本人做过多次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}