东方星雨

简单网络

一个爱好网络的80后男站长。

关注我东方星雨个人微信号:476847113

您现在的位置是:首页 > 站长日志

帝国cms插件 在模板中修改字段值

2020-04-02 站长 站长日志

在帝国cms 的内容模板中,我们有时候希望临时修改字段值。

比如newstext字段,只是想临时修改下,不想修改数据库的原值。

一般的操作方法是:用php代码替换内容模板中的[!--newstext--]标签,例如这样---

<?
//$artilce_body =$navinfor['newstext'];
$artilce_body =stripslashes($navinfor['newstext']);

$navinfor['newstext']= str_ireplace('帮帮我', 'jiuhecai', $artilce_body);

echo $navinfor['newstext'];
?>

目的是达到了,但是如果newstext有分页的话,你就悲剧了。分页掉了!

大神jiuhecai研究了帝国cms 的源代码,给出了解决方法:

针对帝国cms 的源码文件e/class/functions.php 修改两个地方:

1. 查找$GLOBALS['navinfor']=$add;

修改为 $GLOBALS['navinfor']=&$add;

2.查找function GetInfoNewsBq($classid,$newstemp_r,$ecms_gr,$docheckrep){

修改为 function GetInfoNewsBq($classid,$newstemp_r,&$ecms_gr,$docheckrep){

 

修改的原理是,使用数组传地址的方式,加强$navinfor变量和$add(存储的某条信息主附表所有字段值)的联系,使得模板中对字段值的修改能够传回标签。

这样修改后,上述例子这样处理:

<?
//$artilce_body =$navinfor['newstext'];
$artilce_body =stripslashes($navinfor['newstext']);

$navinfor['newstext']= str_ireplace('帮帮我', 'jiuhecai', $artilce_body);

?>
[!--newstext--]

我们依然可以使用newstext标签,分页自然完好,但是标签的值,的确被我们改变了。

 

文章评论