dedecms插件开发简明教程
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>本文简单讲述了dedecms插件开发的方法。分享给大家供大家参考。具体如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
这里举的是一个很简单插件实例,通过此插件,你可以知道怎么样开发一个插件,它结构是怎么设置的,数据库,后台等。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
文件结构如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
enroll.php 文件在 plus文件下<br>
enroll.htm文件在templets/plus 文件夹下<br>
adenroll.php 文件在dede文件夹下<br>
adenroll.html 文件dede/templet文件夹下</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
sql文件如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
代码如下:</div>
<div class="msgborder" id="phpcode5" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
CREATE TABLE IF NOT EXISTS `dede_enroll` (<br>
`id` int(4) NOT NULL auto_increment,<br>
`name` varchar(20) NOT NULL,<br>
`mail` varchar(30) NOT NULL,<br>
`tag` tinyint(1) NOT NULL default '0',<br>
PRIMARY KEY (`id`)<br>
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;<br><br>
INSERT INTO `dede_plus` (`aid`, `plusname`, `menustring`, `mainurl`, `writer`, `isshow`, `filelist`) VALUES<br>
(30, '网上报名', '<m:item name=''网上报名'' link=''adenroll.php'' rank=''plus_网上报名'' target=''main'' />', '', 'g1000', 1, '');</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
这里说明下 为了方便 我简单的设置了 两个字段 姓名和邮箱 tag字段是标示是否录取 1为录取<br>
第一个insert语句是添加到后台管理<br>
第二个insert语句是添加到前台导航栏</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
enroll.php文件如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
代码如下:</div>
<div class="msgborder" id="phpcode6" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<?php <br>
//*******要先包含common.inc.php 然后 session_start(); 否则取不到session的值 <br>
//*******因为common.inc.php 有关于session路径的配置 <br>
include_once dirname(__FILE__).'./../include/common.inc.php';//包含配置文件 <br>
session_start(); <br>
require_once DEDEINC."/arc.partview.class.php";//包含partiew类 <br>
//*****实例化 这个类的作用是得到头部导航栏和尾部信息 若不需要可以使用dedetemplate.class.php 这个类 <br>
$pv = new PartView(); <br>
if($_POST){ <br>
if( CheckEmail($_POST['mail'])==false){//验证邮箱 方法在common.func.php 公用函数 <br>
ShowMsg('邮箱格式错误','-1'); <br>
exit(); <br>
} <br>
if($_POST['name']==""){ <br>
ShowMsg('用户名不能为空','-1'); <br>
exit(); <br>
}else{ <br>
$name=htmlspecialchars($_POST['name']); <br>
} <br>
if($_SESSION['dd_ckstr']!=strtolower($_POST['validation'])){//验证 验证码 必须转换成小写 <br>
ShowMsg('验证码错误',-1); <br>
exit(); <br>
} <br>
$sql="insert into `cms_enroll`(name,mail) values('$name','$_POST')"; <br>
//********$db可直接使用 系统自动实例化了dedesql.class.php <br>
$affected = $db->ExecuteNoneQuery2($sql);//执行一条语句 返回影响值 <br>
if($affected){ <br>
ShowMsg('报名成功',-1); <br>
} <br>
}else{ <br>
$pv->SetTemplet(DEDETEMPLATE.'/plus/enroll.htm');//设置模板 <br>
$pv->Display();//显示页面 <br>
}<br>
?></div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
enroll.htm文件如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
代码如下:</div>
<div class="msgborder" id="phpcode7" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"> <br>
<head> <br>
<title>{dede:global.cfg_webname/}-在线报名</title> <br>
<link href="{dede:global.cfg_templeturl/}/style/dedecms.css" rel="stylesheet" media="screen" type="text/css" /> <br>
</script> <br>
</head> <br>
<body> <br>
{dede:include filename="../default/head.htm"/}<!-- 包含头部 --> <br>
<blockquote > <br>
<form method="post" action=""> <br>
姓 名:<input type="text" size=30 name="name" /><br><br>
邮 箱:<input type="text" size=30 name="mail" /><br><br>
<!--vdimgck.php 是验证码--> <br>
验证码:<input type="text" name="validation" /><img src="../../include/vdimgck.php" /><br><br>
<input name="encoll" type="submit" value="报名" /><br><br>
</form> <br>
</blockquote> <br>
{dede:include filename="../default/footer.htm"/}<!-- 包含尾部 --> <br>
</body> <br>
</html></div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
adenroll.php如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
代码如下:</div>
<div class="msgborder" id="phpcode8" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<?php <br>
require_once(dirname(__FILE__).'/config.php');//后台配置文件 检查登陆 配置信息 <br>
require_once(DEDEINC."/datalistcp.class.php");//包含分页类 <br>
if($_GET['action']&&$_GET['id']){ <br>
if($_GET['action']=='pass'){//各种操作 <br>
$db->ExecuteNoneQuery("update cms_enroll set `tag`=1 where id='$_GET'"); <br>
ShowMsg('录取成功','adenroll.php'); <br>
} <br>
if($_GET['action']=='nopass'){ <br>
$db->ExecuteNoneQuery("update cms_enroll set `tag`=0 where id='$_GET'"); <br>
ShowMsg('取消录取','adenroll.php'); <br>
} <br>
if($_GET['action']=='delete'){ <br>
$db->ExecuteNoneQuery("delete from cms_enroll where id='$_GET'"); <br>
ShowMsg('删除成功','adenroll.php'); <br>
} <br>
}else{ <br>
$dl = new DataListCP(); <br>
$dl->pageSize = 10;//每页显示10条 <br>
$dl->SetTemplate('./templets/adenroll.htm');//载入模板 <br>
$sql="select * from cms_enroll"; <br>
$dl->SetSource($sql);//执行sql 不能与$dl->SetTemplate 颠倒 <br>
$dl->Display();//显示页面 <br>
}<br>
?></div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
adenroll.html文件如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
代码如下:</div>
<div class="msgborder" id="phpcode9" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"> <br>
<head> <br>
<title>在线报名管理</title> <br>
<link href='img/base.css' rel='stylesheet' type='text/css' /> <br>
<style type="text/css"> <br>
th,td{ <br>
text-align:center; <br>
border:1px #D1DDAA solid; <br>
font-size:15px; <br>
} <br>
th{ <br>
background:#E6F8B7; <br>
} <br>
table{ <br>
margin-top:20px; <br>
} <br>
</style> <br>
</head> <br>
<body> <br>
<table width="90%" border="0" cellpadding="0" cellspacing="0" align="center"> <br>
<tr> <br>
<th>姓名</th> <br>
<th>E-mail</th> <br>
<th>状态</th> <br>
<th>操作</th> <br>
</tr> <br>
<!-- 循环得到结果 --> <br>
{dede:datalist} <br>
<tr> <br>
<td>{dede:field.name /}</td> <br>
<td>{dede:field.mail /}</td> <br>
<td> <br>
{dede:if field.tag==0} <br>
未录取 <br>
{else} <br>
<font color="red">已录取</font> <br>
{/dede:if} <br>
</td> <br>
<td> <a href="adenroll.php?action=pass&id={dede:field.id /}">[录取]</a> <br>
| <br>
<a href="adenroll.php?action=nopass&id={dede:field.id /}">[不通过]</a> <br>
| <br>
<a href="adenroll.php?action=delete&id={dede:field.id /}">[删除]</a> <br>
</td> <br>
</tr> <br>
{/dede:datalist} <br>
</table> <br>
<!-- 分页标签 --> <br>
<p>{dede:pagelist listitem="info,index,end,pre,next,pageno" listsize="5"/}</p> <br>
</body> <br>
</html></div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
希望本文所述对大家的dedecms二次开发有所帮助。</p>
頁:
[1]