DEDECMS解析模板之灵活应用视图类
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>下面我们就简单的创建一个属于自己的php页面处理文件,在文件里,用织梦自身的模板引擎和视图,去解析我预先创建好的静态html文件。在此,我简单的写了如下几段代码:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
第一步,创建自己的php页面处理文件,在这里,我在根目录下创建demo.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="phpcode2" 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";'>
<br>
<?php<br>
/*************************************************************************<br>
* <br>
* <br>
* 说 明:织梦解析模板之灵活应用视图类<br>
* <br>
* 作 者:郑州北鲨<br>
* <br>
* 备 注:织梦v5+模板引擎,分为两种,<br>
* 1、静态模板引擎(include/dedetag.class.php) DedeCMS V5.3 及之前版本使用的主要的模板类,它是解析式模板类,并非编译式的。<br>
* (注:编译式是通过获得标签位置进行内容替换,编译式是直接解析为 PHP 代码,二次执行。)<br>
* 2、动态模板引擎(include/dedetemplate.class.php)<br>
* 可以根据自己的实际需求,修改或创建自己的视图类,让后通过织梦提供的模板引擎,去解析处理即可。<br>
* <br>
* ***********************************************************************/<br>
/*第一步>>引入公用配置:<br>
* common.inc.php作用:<br>
* 该文件里面进行了系统全局配置、全局常用函数common.func.php、<br>
* 模块MVC框架需要的控制器和模型基类(control.class.php,model.class.php)、载入小助手配置、<br>
* 设定缓存配置信息、特殊全局变量、系统配置参数、数据库配置文件(data/common.inc.php)、载入系统验证安全配置、<br>
* Session跨域设置、$cfg_相关的参数配置信息等这些模块功能的配置。<br>
* <br>
* <br>
* */<br>
require 'include/common.inc.php';<br>
//第二步>>引入视图类<br>
require 'include/arc.partview.class.php';<br>
//第三步>>实例化视图对象<br>
$pv=new PartView();<br>
//第四步>>设置视图模板<br>
$pv->SetTemplet("demo.html");<br>
//最后>显示视图<br>
$pv->Display();<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";'>
第二步,创建模板页面。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
懒人省事,同样的我在根目录下创建了demo.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="phpcode3" 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";'>
<br>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><br>
<html><br>
<head><br>
<meta http-equiv="Content-Type" content="text/html; charset="><br>
<title>demo测试视图</title><br>
<STYLE type=" text/css"><br>
body{font-size:12px;}<br>
ul li{float:left; list-style:none;padding:2px 10px;}<br>
ul li a{ }<br>
#arclist li{ clear:both;float:none;}<br>
</STYLE><br>
</head><br>
<body><br>
<!-- channel_type标签测试 --><br>
<ul><br>
{dede:channel type='top' row='10' current}<br>
<li><a href='' ><span></span></a></li><br>
{/dede:channel}<br>
<!--arclist标签测试 --><br>
<ul id="arclist"><br>
{dede:arclist row="10"}<br>
<li></li><br>
{/dede:arclist}<br>
</ul><br>
</ul><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";'>
在demo.html文件中,我以{dede:channel}和{dede:arclist}这两个标签来测试程序,运行结果如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<img style="max-width:100%!important;height:auto!important;"title="DEDECMS解析模板之灵活应用视图类" alt="DEDECMS解析模板之灵活应用视图类" id="theimg" src="https://zhuji.jb51.net/uploads/img/202305/1ae0faca8e60829b655098b5b65fddb1.jpg"></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>
頁:
[1]