最心动的相遇 發表於 2024-1-14 00:00:00

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, '网上报名', '&lt;m:item name=''网上报名'' link=''adenroll.php'' rank=''plus_网上报名'' target=''main'' /&gt;', '', '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";'>
        &lt;?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-&gt;ExecuteNoneQuery2($sql);//执行一条语句 返回影响值 <br>
        if($affected){ <br>
        ShowMsg('报名成功',-1); <br>
        } <br>
        }else{ <br>
        $pv-&gt;SetTemplet(DEDETEMPLATE.'/plus/enroll.htm');//设置模板 <br>
        $pv-&gt;Display();//显示页面 <br>
        }<br>
        ?&gt;</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";'>
        &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "&lt;a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&lt;/a&gt;"&gt; <br>
        &lt;head&gt; <br>
        &lt;title&gt;{dede:global.cfg_webname/}-在线报名&lt;/title&gt; <br>
        &lt;link href="{dede:global.cfg_templeturl/}/style/dedecms.css" rel="stylesheet" media="screen" type="text/css" /&gt; <br>
        &lt;/script&gt; <br>
        &lt;/head&gt; <br>
        &lt;body&gt; <br>
        {dede:include filename="../default/head.htm"/}&lt;!-- 包含头部 --&gt; <br>
        &lt;blockquote &gt; <br>
        &lt;form method="post" action=""&gt; <br>
        姓 名:&lt;input type="text" size=30 name="name" /&gt;<br><br>
        邮 箱:&lt;input type="text" size=30 name="mail" /&gt;<br><br>
        &lt;!--vdimgck.php 是验证码--&gt; <br>
        验证码:&lt;input type="text" name="validation" /&gt;&lt;img src="../../include/vdimgck.php" /&gt;<br><br>
        &lt;input name="encoll" type="submit" value="报名" /&gt;<br><br>
        &lt;/form&gt; <br>
        &lt;/blockquote&gt; <br>
        {dede:include filename="../default/footer.htm"/}&lt;!-- 包含尾部 --&gt; <br>
        &lt;/body&gt; <br>
        &lt;/html&gt;</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";'>
        &lt;?php <br>
        require_once(dirname(__FILE__).'/config.php');//后台配置文件 检查登陆 配置信息 <br>
        require_once(DEDEINC."/datalistcp.class.php");//包含分页类 <br>
        if($_GET['action']&amp;&amp;$_GET['id']){ <br>
        if($_GET['action']=='pass'){//各种操作 <br>
        $db-&gt;ExecuteNoneQuery("update cms_enroll set `tag`=1 where id='$_GET'"); <br>
        ShowMsg('录取成功','adenroll.php'); <br>
        } <br>
        if($_GET['action']=='nopass'){ <br>
        $db-&gt;ExecuteNoneQuery("update cms_enroll set `tag`=0 where id='$_GET'"); <br>
        ShowMsg('取消录取','adenroll.php'); <br>
        } <br>
        if($_GET['action']=='delete'){ <br>
        $db-&gt;ExecuteNoneQuery("delete from cms_enroll where id='$_GET'"); <br>
        ShowMsg('删除成功','adenroll.php'); <br>
        } <br>
        }else{ <br>
        $dl = new DataListCP(); <br>
        $dl-&gt;pageSize = 10;//每页显示10条 <br>
        $dl-&gt;SetTemplate('./templets/adenroll.htm');//载入模板 <br>
        $sql="select * from cms_enroll"; <br>
        $dl-&gt;SetSource($sql);//执行sql 不能与$dl-&gt;SetTemplate 颠倒 <br>
        $dl-&gt;Display();//显示页面 <br>
        }<br>
        ?&gt;</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";'>
        &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""&lt;a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&lt;/a&gt;"&gt; <br>
        &lt;head&gt; <br>
        &lt;title&gt;在线报名管理&lt;/title&gt; <br>
        &lt;link href='img/base.css' rel='stylesheet' type='text/css' /&gt; <br>
        &lt;style type="text/css"&gt; <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>
        &lt;/style&gt; <br>
        &lt;/head&gt; <br>
        &lt;body&gt; <br>
        &lt;table width="90%" border="0" cellpadding="0" cellspacing="0" align="center"&gt; <br>
        &lt;tr&gt; <br>
        &lt;th&gt;姓名&lt;/th&gt; <br>
        &lt;th&gt;E-mail&lt;/th&gt; <br>
        &lt;th&gt;状态&lt;/th&gt; <br>
        &lt;th&gt;操作&lt;/th&gt; <br>
        &lt;/tr&gt; <br>
        &lt;!-- 循环得到结果 --&gt; <br>
        {dede:datalist} <br>
        &lt;tr&gt; <br>
        &lt;td&gt;{dede:field.name /}&lt;/td&gt; <br>
        &lt;td&gt;{dede:field.mail /}&lt;/td&gt; <br>
        &lt;td&gt; <br>
        {dede:if field.tag==0} <br>
        未录取 <br>
        {else} <br>
        &lt;font color="red"&gt;已录取&lt;/font&gt; <br>
        {/dede:if} <br>
        &lt;/td&gt; <br>
        &lt;td&gt; &lt;a href="adenroll.php?action=pass&amp;id={dede:field.id /}"&gt;[录取]&lt;/a&gt; <br>
        | <br>
        &lt;a href="adenroll.php?action=nopass&amp;id={dede:field.id /}"&gt;[不通过]&lt;/a&gt; <br>
        | <br>
        &lt;a href="adenroll.php?action=delete&amp;id={dede:field.id /}"&gt;[删除]&lt;/a&gt; <br>
        &lt;/td&gt; <br>
        &lt;/tr&gt; <br>
        {/dede:datalist} <br>
        &lt;/table&gt; <br>
        &lt;!-- 分页标签 --&gt; <br>
        &lt;p&gt;{dede:pagelist listitem="info,index,end,pre,next,pageno" listsize="5"/}&lt;/p&gt; <br>
        &lt;/body&gt; <br>
        &lt;/html&gt;</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]
查看完整版本: dedecms插件开发简明教程