3.1.3 - 普通 - 未处理
版主不知道 这个算不算BUG这个是问题贴http://www.thinkphp.cn/topic/4416.html
文档 8.7 用变量控制要导入的模版
=QTE=
5、 用变量控制要导入的模版
格式:<include file="$变量名" />
例如
<include file="$tplName" />
=UNQTE=
我想用这个特性,灵活组装一个页面。
但是 发现有问题,
// FirstAction.class.php
class FirstAction extends Action {
public function mainpage() {
$table = "First:table";
$this->assign("table", $table);
$this->display("Root:mainpage");
}
}
// SecondAction.class.php
class SecondAction extends Action {
public function mainpage(){
$table="Second:table";
$this->assign("table",$table);
$this->display("Root:mainpage");
}
}
//Tpl/Root/mainpage.html
<html>
<head>
<ti
<me
</head>
<body>
<B>Root:mainpage</B><br>
<include file="$table"/>
</body>
</html>
我在浏览器里输入http://127.0.0.1/myapp/index.php/First/mainpage
显示
”Root:mainpage
First:table “
第二次输入
http://127.0.0.1/myapp/index.php/Secod/mainpage
还是显示
”Root:mainpage
First:table “
我看了下 Runtime/Cache 只有一个缓存的php。
说明<include file="$tplName" />只能使用一次~~~
有啥方法可以多次重复组装?
PS:
1.附件解压加上ThinkPHP核心库可以运行
2.我想了个解决方法
用Action的$this->fetch() 方法读页面再赋变量
$table="Second:table";
$content = $this->fetch($table);
$this->assign("table",$content );
$this->display("Root:mainpage");
// mainpage.html
<body>
<B>Root:mainpage</B><br>
{$table} <!--<include file="$table"/>-->
</body>
但是这样每次调用mainpage的方法都会多一次IO操作,没有用模板的意义了。
