调用方法:
<?php
include('../../php4/ZxPhpLib.php');
require_once('ZxTemplate.php');
$t=new ZxTemplate;
$t->assignSimple('tag','tempVar');
$t->assignSimple('ttt1','listVar');
$t->assignComplex('list','showList');
$t->loadFile('temp.tpl.php',0);function tempVar($tag) {
return $tag->attributes['value']."<br>\n";
}function listVar($tag) {
static $i=0;
return ++$i;
}function showList($tag) {
$count=(int)$tag->attributes['loop'];
$s='';
for($i=0;$i<$count;$i++) {
$s.=trim($tag->text)."<br>\n";
}
return $s;
}
?>解析结果:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>
<body>
PHP<br>JSP<br>1<br>
2<br>
3<br>
4<br>
5<br></body>
</html>
<?php
include('../../php4/ZxPhpLib.php');
require_once('ZxTemplate.php');
$t=new ZxTemplate;
$t->assignSimple('tag','tempVar');
$t->assignSimple('ttt1','listVar');
$t->assignComplex('list','showList');
$t->loadFile('temp.tpl.php',0);function tempVar($tag) {
return $tag->attributes['value']."<br>\n";
}function listVar($tag) {
static $i=0;
return ++$i;
}function showList($tag) {
$count=(int)$tag->attributes['loop'];
$s='';
for($i=0;$i<$count;$i++) {
$s.=trim($tag->text)."<br>\n";
}
return $s;
}
?>解析结果:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>
<body>
PHP<br>JSP<br>1<br>
2<br>
3<br>
4<br>
5<br></body>
</html>
写做这样可能好些
<select tag=php datasrc="test">
...
</select>
但是这样可以有更多的定制功能,更加灵活
用datasize来指定数据规模。虽然并不是每个html标记都有这些属性,但由于是充当php的模板。所以并没有什么问题。
如果这几个属性按html规则书写,在加上xml文档,那么ie就会自动进行显示了
还是用smarty习惯一点
不过我对可视不可视到是无所谓,神仙这个确实很灵活的
关注下面高手的见解
模板的初衷就是为了实现mvc,能在一定程度上分离页面和程序就足够了
------------
唠叨说的好象有点象.net里的html控件的思想啊
我写了dreamweaver的插件,这样在dw里面就能看见一个图标了
<php:list loop="5">
是典型的.net风格
不过.net和java都是互相学,
也有很多高手用php实现类似jsp的用的那种架构
以后谁能都统一了才好呢,呵呵