您当前的位置:首页 > 网站建设笔记 >

帝国cms 数据表如何增加一个类似相关链接的系统字段

0

首先,第一步在数据表phome_ecms_shop_data_1(商城系统数据副表)上添加一个名字为shiyongid的字段,使用phpmyadmin打开该数据表,执行以下SQL语句:

ALTER TABLE `phome_ecms_shop_data_1` ADD `shiyongid` CHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' AFTER `keyid`

也可以使用phpmyadmin的操作界面上进行添加,如下图所示:

使用phpmyadmin在数据表上添加字段前选择插入位置
使用phpmyadmin在数据表上添加字段前选择该字段的插入位置

使用phpmyadmin在数据表上添加字段
除了名字之外,其他(类型、长度/值、默认、整理)都跟相关链接keyid字段的一样填写,填写完之后点击保存按钮。

第二步,打开/e/admin/AddNews.php文件,按照以下提示添加额外的代码并保存。

//找到以下代码
<?php
include($modfile);
?>
//在以上代码下面添加以下代码
<?php
if(!empty($classid) && $classid==10){
?>
<table width="100%" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="16%" height="25">适用模型</td>
<td>
	<a href="javascript:;" title="查看和编辑适用模型" onclick="window.open('info/OtherProduct.php?<?=$ecms_hashur['ehref']?>&classid=<?=$classid?>&id=<?=$id?>&enews=<?=$enews?>&form=add&field=info_shiyongid&shiyongid='+document.add.info_shiyongid.value+'&keyboard='+encodeURIComponent(document.add.keyboard.value)+'&title='+encodeURIComponent(document.add.title.value),'','width=800,height=550,scrollbars=yes,resizable=yes');">编辑适用模型</a>
	<input name="info_shiyongid" type="hidden" id="info_shiyongid" value="<?=$r[shiyongid]?>">
</td>
</tr>
</table>
<?php
}
?>

第三步,在/e/admin/info文件夹里新建以下三个文件:
OtherProduct.php
OtherProductShow.php
OtherProductSearch.php
已为你准备好,可点击下载

第四步,打开/e/class/connect.php文件,搜索function ReturnSqlFtextF($mid)函数,并修改为如下代码所示:

//返回内容副表查询字段
function ReturnSqlFtextF($mid){
	global $emod_r;
	if(empty($mid))
	{
		return "*";
	}
	//为商品系统模型时,添加shiyongid字段
	if(!empty($mid) && $mid==6)
	{
		$f="keyid,shiyongid,dokey,newstempid,closepl,infotags".substr($emod_r[$mid]["tbdataf"],0,-1);
	}
	else
	{
		$f="keyid,dokey,newstempid,closepl,infotags".substr($emod_r[$mid]["tbdataf"],0,-1);
	}
	return $f;
}

第五步,打开/e/class/hinfofun.php文件,在文件里面添加一个适用模型ID处理的函数,如下代码所示:

//适用模型ID处理
function DoPostDiyShiyongID($shiyongid){
	if(!$shiyongid||$shiyongid==",")
	{
		return "";
	}
	$new_shiyongid="";
	$dh="";
	$r=explode(",",$shiyongid);
	$count=count($r);
	for($i=0;$i<$count;$i++)
	{
		$r[$i]=(int)$r[$i];
		if(!$r[$i])
		{
			continue;
		}
		$new_shiyongid.=$dh.$r[$i];
		$dh=",";
	}
	return $new_shiyongid;
}

接着需要修改AddNews()函数和EditNews()函数,AddNews()函数涉及的修改如下代码所示:

//Begin找到以下这段代码
//返回关键字组合
if($add['info_diyotherlink'])
{
	$keyid=DoPostDiyOtherlinkID($add['info_keyid']);
}
else
{
	$keyid=GetKeyid($add[keyboard],$add[classid],0,$class_r[$add[classid]][link_num]);
}
//End

//在以上代码段的下面添加以下代码,增加信息时需要处理适用模型字段的值。

//商品系统模型ID等于6
if($class_r[$add[classid]][modid] == 6) $shiyongid = DoPostDiyShiyongID($add['info_shiyongid']);
//Begin找到以下这段代码
//副表
$finfosql=$empire->query("insert into ".$infotbr['datatbname']."(id,classid,keyid,dokey,newstempid,closepl,haveaddfen,infotags".$ret_r['datafields'].") values('$id','$add[classid]','$keyid','$add[dokey]','$add[newstempid]','$add[closepl]',0,'".addslashes($add[infotags])."'".$ret_r['datavalues'].");");
//End

//将以上代码段修改为以下的代码段。

//副表
//商品系统模型ID等于6
if($class_r[$add[classid]][modid] == 6)
{
	$finfosql=$empire->query("insert into ".$infotbr['datatbname']."(id,classid,keyid,shiyongid,dokey,newstempid,closepl,haveaddfen,infotags".$ret_r['datafields'].") values('$id','$add[classid]','$keyid','$shiyongid','$add[dokey]','$add[newstempid]','$add[closepl]',0,'".addslashes($add[infotags])."'".$ret_r['datavalues'].");");
}
else
{
	$finfosql=$empire->query("insert into ".$infotbr['datatbname']."(id,classid,keyid,dokey,newstempid,closepl,haveaddfen,infotags".$ret_r['datafields'].") values('$id','$add[classid]','$keyid','$add[dokey]','$add[newstempid]','$add[closepl]',0,'".addslashes($add[infotags])."'".$ret_r['datavalues'].");");
}

EditNews()函数涉及的修改如下代码所示:

//Begin找到以下这段代码
//返回关键字组合
if($add['info_diyotherlink'])//1为手动相关链接
{
	$keyid=DoPostDiyOtherlinkID($add['info_keyid']);
}
else//0按关键字查询
{
	$keyid=GetKeyid($add[keyboard],$add[classid],$add[id],$class_r[$add[classid]][link_num]);
}
//End

//在以上代码段的下面添加以下代码,修改信息时需要处理适用模型字段的值。

//商品系统模型ID等于6
if($mid==6) $shiyongid = DoPostDiyShiyongID($add['info_shiyongid']);
//Begin找到以下这段代码
//副表
$stb=$checkr['stb'];
$fsql=$empire->query("update ".$infotbr['datatbname']." set classid='$add[classid]',keyid='$keyid',dokey=$add[dokey],newstempid=$add[newstempid],closepl=$add[closepl],infotags='".addslashes($add[infotags])."'".$ret_r[datavalues]." where id='$add[id]' limit 1");
//End

//将以上代码段修改为以下的代码段。

//副表
$stb=$checkr['stb'];
//商品系统模型ID等于6
if($mid==6)
{
	$fsql=$empire->query("update ".$infotbr['datatbname']." set classid='$add[classid]',keyid='$keyid',shiyongid='$shiyongid',dokey=$add[dokey],newstempid=$add[newstempid],closepl=$add[closepl],infotags='".addslashes($add[infotags])."'".$ret_r[datavalues]." where id='$add[id]' limit 1");
}
else
{
	$fsql=$empire->query("update ".$infotbr['datatbname']." set classid='$add[classid]',keyid='$keyid',dokey=$add[dokey],newstempid=$add[newstempid],closepl=$add[closepl],infotags='".addslashes($add[infotags])."'".$ret_r[datavalues]." where id='$add[id]' limit 1");
}

第六步,在内容模板里填写适用模型字段的输出标签,如下所示:

<p>适用模型:[!--shiyong.link--]</p>

第七步,打开/e/action/ShowInfo.php文件,需要修改里面的DtGetHtml()函数,DtGetHtml()函数涉及的修改如下代码所示:

//Begin找到以下这段代码
//相关信息
if(strstr($newstemptext,'[!--other.link--]'))
{
    $keyboardtext=GetKeyboard($add[keyboard],$add[keyid],$add[classid],$add[id],$class_r[$add[classid]][link_num]);
}
//End

//在以上代码段的下面添加以下代码。

//适用模型
if(strstr($newstemptext,'[!--shiyong.link--]'))
{
    $shiyongtext=GetShiyong($add[shiyongid],$add[classid],$add[id],100);
}
//找到以下这行代码
$newstempstr=str_replace('[!--other.link--]',$keyboardtext,$newstempstr);

//在这行代码下面添加以下这行代码
$newstempstr=str_replace('[!--shiyong.link--]',$shiyongtext,$newstempstr);

第八步,打开/e/class/functions.php文件,在文件里面添加一个取得适用模型的函数和修改里面的RepOtherTemp函数,如下代码所示:

//取得适用模型
function GetShiyong($shiyongid,$classid,$id,$link_num){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre;
	if($shiyongid&&$link_num)
	{
		$add="id in (".$shiyongid.")";
		$tr=$empire->fetch1("select shiyongtemp,shiyongtempsub,shiyongtempdate from ".GetTemptb("enewspubtemp")." limit 1");//取得相关链接模板
		$temp_r=explode("[!--empirenews.listtemp--]",$tr[shiyongtemp]);
		$key_sql=$empire->query("select id,newstime,title,isurl,titleurl,classid,titlepic,model from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where ".$add." order by model asc limit $link_num");
		while($link_r=$empire->fetch($key_sql))
		{
			$shiyongtext.=RepOtherTemp($temp_r[1],$link_r,$tr);
		}
		$shiyongtext=$temp_r[0].$shiyongtext.$temp_r[2];
	}
	else
	{
		$shiyongtext=$fun_r['NotLinkNews'];
	}
	return $shiyongtext;
}

//替换相关链接模板
function RepOtherTemp($temptext,$r,$tr){
	global $public_r,$class_r;
	$title=sub($r[title],0,$tr['otherlinktempsub'],false);
	$r['newstime']=date($tr['otherlinktempdate'],$r['newstime']);
	$titlelink=sys_ReturnBqTitleLink($r);//标题链接
	$temptext=str_replace("[!--title--]",$title,$temptext);
	$temptext=str_replace("[!--oldtitle--]",$r[title],$temptext);
	$temptext=str_replace("[!--titleurl--]",$titlelink,$temptext);
	$temptext=str_replace("[!--newstime--]",$r[newstime],$temptext);
	//添加了以下这行代码(根据你自己的实际情况)
	if($r[model]) $temptext=str_replace("[!--model--]",$r[model],$temptext);
	if(empty($r[titlepic]))
	{
		$titlepic=$public_r[newsurl]."e/data/images/notimg.gif";
	}
	else
	{
		$titlepic=$r[titlepic];
	}
	$temptext=str_replace("[!--titlepic--]",$titlepic,$temptext);
	return $temptext;
}

终于到了最后一步了,就是需要在phome_enewspubtemp数据表中添加三个字段以保存新添加的适用模型字段的模板代码,以下直接给出SQL执行语句,使用phpmyadmin执行就可以了。

ALTER TABLE `phome_enewspubtemp` ADD `shiyongtemp` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `phome_enewspubtemp` ADD `shiyongtempsub` TINYINT(4) NOT NULL DEFAULT '0';
ALTER TABLE `phome_enewspubtemp` ADD `shiyongtempdate` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '';

UPDATE `phome_enewspubtemp` SET `shiyongtemp` = '[!--empirenews.listtemp--]<a href="[!--titleurl--]">[!--model--] [!--oldtitle--]</a>[!--empirenews.listtemp--]' WHERE `phome_enewspubtemp`.`id` =1;
UPDATE `phome_enewspubtemp` SET `shiyongtempsub` = '50' WHERE `phome_enewspubtemp`.`id` =1;
UPDATE `phome_enewspubtemp` SET `shiyongtempdate` = 'Y-m-d H:i:s' WHERE `phome_enewspubtemp`.`id` =1;

建站咨询

在线咨询真诚为您提供专业解答服务

咨询热线

137 1731 25507×24小时服务热线

微信交流

二维码终于等到你,还好我没放弃
返回顶部