phplib使用php与html分离,对流程没有太大的帮助!phplib中较常用的是数据库链接类,好像名称是db_mysql;个人认为phplib比smarty好用.提供一个简单的示像[转载]:
reg.htm
--------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
{top2}{some_color}{some_color2}{test}
<body>
中国人
</body>
</html>reg.php
--------------------------
<?
include "template.inc"; //引用文件
$my_color="blue";
$my_color2="red";
$t = new Template("."); //新的对象,设定Template为模板根目录
$t->set_file("MyFileHandle","reg.htm"); //主模板
$t->set_file("_top", "top.htm");//头部模板
$t->set_file("_test", "test.htm");//头部模板
$t->set_var("some_color",$my_color);
$t->set_var("some_color2",$my_color2);
$t->parse("top2","_top"); //头部分析结果赋予变量top
$t->parse("test","_test"); //头部分析结果赋予变量top
$t->pparse("MyOutput","MyFileHandle"); //分析整个模板
//$t->p("MyOutput");//输出
?>同一目录下放一个template.inc文件;网上有很多例子,找找看!
reg.htm
--------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
{top2}{some_color}{some_color2}{test}
<body>
中国人
</body>
</html>reg.php
--------------------------
<?
include "template.inc"; //引用文件
$my_color="blue";
$my_color2="red";
$t = new Template("."); //新的对象,设定Template为模板根目录
$t->set_file("MyFileHandle","reg.htm"); //主模板
$t->set_file("_top", "top.htm");//头部模板
$t->set_file("_test", "test.htm");//头部模板
$t->set_var("some_color",$my_color);
$t->set_var("some_color2",$my_color2);
$t->parse("top2","_top"); //头部分析结果赋予变量top
$t->parse("test","_test"); //头部分析结果赋予变量top
$t->pparse("MyOutput","MyFileHandle"); //分析整个模板
//$t->p("MyOutput");//输出
?>同一目录下放一个template.inc文件;网上有很多例子,找找看!
关于phplib和smarty的比较,你可以看看这个
http://blog.csdn.net/mynamesucks/archive/2004/08/26/85832.aspx
我写的,写的不好请见量 :>
里面定义的类、函数我怎么才能知道,总不能看源代码吧
这种方法也算是自己的MVC开发模式吧?
PHPLIB同 SMARTY 一个很大的区别就是,PHPLIB没有预处理而SMARTY有。
这就是为什么 SMARTY 第一次访问慢,以后访问比PHPLIB快的根本所在。
SMARTY 太庞大了,用来做中小型网站就是杀鸡用牛刀
PHPLIB用起来比较简单灵活