织梦dedecms插件开发实例

今天制作了一个简单的dedecms用户留言插件,先分享出来,后续可能会发博文总结各种织梦插件制作方法和原理。

插件开发步骤:1、制作程序文件和建立所需用到的表  2、使用模块生成向导生成插件XML 3、安装使用。

下面以我制作的简单用户留言插件为例,演示如下:

一、实现的功能

这个例子实现的功能很简单,只是用来演示插件制作的原理,我们弄清楚原理后,就可以写代码实现其他各种功能。

前台页面:用户可提交留言

织梦dedecms插件开发实例_第1张图片

后台管理页面:

织梦dedecms插件开发实例_第2张图片

二、制作程序文件和在数据库中建立所用到的表。这个小插件用到四个文件和一个表,分别如下:

1、前台表单页面 “/mymessage.htm”。这个页面可放在前台任意位置,也可以放到模板文件夹中使用。实例中我将它放在了网站根目录。





在线留言小插件




留言标题:
留言内容:
验证码: 点击我更换图片

2、保存留言文件  “/plus/mymessage.php”

ExecuteNoneQuery($query);
    ShowMsg('留言成功!','/mymessage.htm');   //这里我图省事儿,直接写绝对路径了,实际应用的时候不应该这样。
}
?>

3、后台管理留言页面 “/后台管理文件夹/templets/mymessage_main.htm”





留言管理






    {dede:datalist}
    
    {/dede:datalist}
  
留言管理
关键字:
选择 留言标题 留言内容 管理
{dede:field.title function='htmlspecialchars(@me)'/} {dede:field.content function='htmlspecialchars(@me)'/} [删除]
  [全选] [取消] 批量删除
{dede:pagelist listsize=6/}

4、后台管理留言PHP文件 "/后台管理文件夹/mymessage_main.php"

ExecuteNoneQuery("DELETE FROM `#@__plus_mymsg` WHERE id='$id'");
    ShowMsg("成功删除一条留言!","mymessage_main.php");
    exit();
}else if($dopost=="delall")
{
    $aids = explode(',',$aids);
    if(isset($aids) && is_array($aids))
    {
        foreach($aids as $aid)
        {
            $aid = preg_replace("#[^0-9]#", "", $aid);
            $dsql->ExecuteNoneQuery("DELETE FROM `#@__plus_mymsg` WHERE id='$aid'");
        }
        ShowMsg("成功删除指定留言!","mymessage_main.php");
        exit();
    }
    else
    {
        ShowMsg("你没选定任何留言!","mymessage_main.php");
        exit();
    }
}else{
	if(empty($keyword)) $keyword = '';
	$sql = "SELECT * FROM `#@__plus_mymsg` WHERE  CONCAT(`title`,`content`) LIKE '%$keyword%'";
	
	$dlist = new DataListCP();
	$dlist->SetParameter('keyword', $keyword);
	$dlist->SetTemplet(DEDEADMIN.'/templets/mymessage_main.htm');
	$dlist->SetSource($sql);
	$dlist->display();
}
?>
5、创建数据表dede_plus_mymsg

DROP TABLE IF EXISTS `dede_plus_mymsg`;
CREATE TABLE `dede_plus_mymsg` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(100) NOT NULL,
  `content` text NOT NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8;
/*需要支持mysql4.0语法,所以使用TYPE=MyISAM*/

二、模块生成向导

织梦dedecms插件开发实例_第3张图片

织梦dedecms插件开发实例_第4张图片

织梦dedecms插件开发实例_第5张图片

安装程序中的代码为:

DROP TABLE IF EXISTS `dede_plus_mymsg`;
CREATE TABLE `dede_plus_mymsg` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(100) NOT NULL,
  `content` text NOT NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8;
/*需要支持mysql4.0语法,所以使用TYPE=MyISAM*/
Delete From `#@__plus` where plusname like '用户留言插件';
INSERT INTO `#@__plus` (`plusname`, `menustring`, `mainurl`, `writer`, `isshow`, `filelist`) VALUES ('用户留言插件', '', '', 'dustin', 1, '');

删除程序中的代码为:

DROP TABLE IF EXISTS `dede_plus_mymsg`;

Delete From `#@__plus` where plusname like '用户留言插件';

三、第三步,模块管理-安装

安装完成后就可以使用了。

四、安装新插件,可以直接上传XML文件。

织梦dedecms插件开发实例_第6张图片

五、本插件生成的XML模块包,如下:



name=用户留言插件
team=dustin
time=2014-11-20
[email protected]
url=http://blog.csdn.net/dustin_php
hash=c6ac1c9a29c2367b12dca0a9f8f3ba55
indexname=
indexurl=
ismember=0
autosetup=1
autodel=1
lang=utf-8
moduletype=plus






PHAgc3R5b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