加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > 开发教程

插件二次开发格式建议

时间:2025-03-29 17:58:07  来源:  作者:

插件二次开发格式建议
帝国CMS6.6版默认增加了“/e/extend/”目录来存放扩展程序。下面以目录格式介绍:
插件程序存放目录用: /e/extend/插件名称目录/
插件程序模板存放目录用: /e/extend/插件名称目录/template/
 
如:以显示“Hello,World”为例子,目录名用“helloworld”,目录格式为:
插件程序存放目录用: /e/extend/helloworld/
插件程序模板存放目录用: /e/extend/helloworld/template/

 


显示“Hello,world”程序编写例子
程序代码编写
存放目录格式:
插件程序存放目录用: /e/extend/helloworld/
插件程序模板存放目录用: /e/extend/helloworld/template/
所需程序文件:
/e/extend/helloworld/index.php 主程序文件
/e/extend/helloworld/template/index.temp.php 主程序模板文件
 
程序目录 模板目录
 
 
主程序文件内容(/e/extend/helloworld/index.php):
<?php
require('../../class/connect.php'); //引入数据库配置文件和公共函数文件
require('../../class/db_sql.php'); //引入数据库操作文件
$link=db_connect(); //连接MYSQL
$empire=new mysqlquery(); //声明数据库操作类
$editor=1; //声明目录层次$context='Hello, World!'; //定义显示内容
require('template/index.temp.php'); //导入模板文件

db_close(); //关闭MYSQL链接
$empire=null; //注消操作类变量
?>
主程序模板文件内容(/e/extend/helloworld/template/index.temp.php):
<?php
if(!defined('InEmpireCMS'))
{
        exit();
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>显示<?=$context?>例子</title>
</head>
<body>
<br>
<br>
<br>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td height="25"><strong>显示内容为如下:</strong></td>
  </tr>
  <tr>
    <td height="60" bgcolor="#FFFFFF"> <div align="center"><strong><font color="#FF0000" size="5"><?=$context?></font></strong></div></td>
  </tr>
</table>
</body>
</html>
说明:模板可用Dreamweaver可视化制作。其中蓝色部分代码为不允许直接访问模板文件的作用。
 
访问Hello World插件文件主程序:/e/extend/helloworld/index.php

 

显示最新10条新闻程序编写例子
程序代码编写
存放目录格式:
插件程序存放目录用: /e/extend/newnews/
插件程序模板存放目录用: /e/extend/newnews/template/
所需程序文件:
/e/extend/newnews/index.php 主程序文件
/e/extend/newnews/template/index.temp.php 主程序模板文件
 
程序目录 模板目录
 
 
主程序文件内容(/e/extend/newnews/index.php):
<?php
require('../../class/connect.php'); //引入数据库配置文件和公共函数文件
require('../../class/db_sql.php'); //引入数据库操作文件
require('../../data/dbcache/class.php'); //引入栏目缓存文件
$link=db_connect(); //连接MYSQL
$empire=new mysqlquery(); //声明数据库操作类
$editor=1; //声明目录层次$sql=$empire->query("select * from {$dbtbpre}ecms_news order by newstime limit 10"); //查询新闻表最新10条记录
require('template/index.temp.php'); //导入模板文件

db_close(); //关闭MYSQL链接
$empire=null; //注消操作类变量
?>
主程序模板文件内容(/e/extend/newnews/template/index.temp.php):
<?php
if(!defined('InEmpireCMS'))
{
        exit();
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>显示最新10条新闻例子</title>
</head>
<body>
<br>
<br>
<br>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td height="25"><strong>显示最新10条新闻:</strong></td>
  </tr>
  <tr>
    <td height="25" bgcolor="#FFFFFF">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <?php
                while($r=$empire->fetch($sql))        //循环获取查询记录
                {
                        $titleurl=sys_ReturnBqTitleLink($r);        //标题链接
                ?>
                <tr>
                <td width="67%" height="25">·<a href="<?=$titleurl?>" target="_blank">
                <?=esub(stripslashes($r[title]),32)?>
                </a></td>
                <td width="33%"><div align="center">[<?=date('Y-m-d',$r[newstime])?>]</div></td>
                </tr>
                <?php
                }
                ?>
                </table>

    </td>
  </tr>
</table>
</body>
</html>
说明:模板可用Dreamweaver可视化制作。其中蓝色部分代码为不允许直接访问模板文件的作用。
 
访问Hello World插件文件主程序:/e/extend/newnews/index.php

 

分类信息分页列表程序编写例子
程序代码编写
存放目录格式:
插件程序存放目录用: /e/extend/infolist/
插件程序模板存放目录用: /e/extend/infolist/template/
所需程序文件:
/e/extend/infolist/index.php 主程序文件
/e/extend/infolist/template/index.temp.php 主程序模板文件
 
程序目录 模板目录
 
 
主程序文件内容(/e/extend/infolist/index.php):
<?php
require('../../class/connect.php'); //引入数据库配置文件和公共函数文件
require('../../class/db_sql.php'); //引入数据库操作文件
require('../../data/dbcache/class.php'); //引入栏目缓存文件
require '../'.LoadLang("pub/fun.php"); //引入分页语言包文件
$link=db_connect(); //连接MYSQL
$empire=new mysqlquery(); //声明数据库操作类
$editor=1; //声明目录层次
//-------- 分页参数 --------
$page=(int)$_GET['page'];
$start=0;
$line=10; //每页显示记录数
$page_line=8; //每页显示分页链接数
$offset=$page*$line; //总偏移量

//-------- 查询SQL --------
//取得信息总数
$totalquery="select count(*) as total from {$dbtbpre}ecms_info where checked=1";
$num=$empire->gettotal($totalquery);
//select查询SQL
$query="select * from {$dbtbpre}ecms_info where checked=1";
$query.=" order by newstime desc limit $offset,$line";
$sql=$empire->query($query);

$listpage=page1($num,$line,$page_line,$start,$page,$search);//取得分页导航
require('template/index.temp.php'); //导入模板文件

db_close(); //关闭MYSQL链接
$empire=null; //注消操作类变量
?>
主程序模板文件内容(/e/extend/infolist/template/index.temp.php):
<?php
if(!defined('InEmpireCMS'))
{
        exit();
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>分类信息分页列表</title>
<link href="template/images/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<br>
<br>
<br>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td height="25"><strong>分类信息分页列表:</strong></td>
  </tr>
  <tr>
    <td height="25" bgcolor="#FFFFFF">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <?php
                while($r=$empire->fetch($sql))        //循环获取查询记录
                {
                        $titleurl=sys_ReturnBqTitleLink($r);        //标题链接
                ?>
                <tr>
                <td width="74%" height="25">
                    <img src="template/images/arrow.gif" border="0" align="absmiddle">&nbsp;[<a href="<?=$public_r[newsurl]?>e/action/ListInfo.php?classid=<?=$r[classid]?>&amp;ph=1&amp;myarea=<?=$r[myarea]?>"><?=$r[myarea]?></a>] <a href="<?=$titleurl?>" target="_blank">
                <?=esub(stripslashes($r[title]),32)?>
                </a></td>
                <td width="26%"><div align="center">
                <?=date('Y-m-d',$r[newstime])?>
                </div></td>
                </tr>
                <?php
                }
                ?>
                </table>

    </td>
  </tr>
  <tr>
    <td height="30" bgcolor="#FFFFFF">
      <div class="epages">
        <?=$listpage?>
      </div></td>
  </tr>
</table>
</body>
</html>
说明:模板可用Dreamweaver可视化制作。其中蓝色部分代码为不允许直接访问模板文件的作用。
 
访问Hello World插件文件主程序:/e/extend/newnews/index.php

 

来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
相关文章
    无相关信息
栏目更新
栏目热门