我建立了一个test.php文件:<?php
include("smarty_inc.php");
$smarty->assign("sort", "Hello World!");
$smarty->display("temp.html");
?>
然后有了它的模板文件:temp.html<html>
<head>
</head>
<body>
<b style="color:red;">{$sort}</b><br/>
</body>
</html>
然后页面上显示了:Hello World! 这个没有任何问题。但是,我在第二个php页面中要引用上面的信息,文件如下:我建立了一个test1.php文件:<?php
include("smarty_inc.php");
$smarty->display("temp1.html");
?>
然后有了它的模板文件:temp1.html<html>
<head>
</head>
<body>
{include_php file="test.php"} {*这里引用了test.php文件*}
<h1>{$sort}</h1>
</body>
</html>
但是运行test1.php文件后,发现在temp1.html中的{$sort}的值没有,而在temp.html的{$sort}值是有的。
就是为什么引用上个页面的内容,为什么上个页面的变量在当前页面没有值。
如果需要访问引用页面的值,应该怎样做,谢谢各位大大!
include("smarty_inc.php");
$smarty->assign("sort", "Hello World!");
$smarty->display("temp.html");
?>
然后有了它的模板文件:temp.html<html>
<head>
</head>
<body>
<b style="color:red;">{$sort}</b><br/>
</body>
</html>
然后页面上显示了:Hello World! 这个没有任何问题。但是,我在第二个php页面中要引用上面的信息,文件如下:我建立了一个test1.php文件:<?php
include("smarty_inc.php");
$smarty->display("temp1.html");
?>
然后有了它的模板文件:temp1.html<html>
<head>
</head>
<body>
{include_php file="test.php"} {*这里引用了test.php文件*}
<h1>{$sort}</h1>
</body>
</html>
但是运行test1.php文件后,发现在temp1.html中的{$sort}的值没有,而在temp.html的{$sort}值是有的。
就是为什么引用上个页面的内容,为什么上个页面的变量在当前页面没有值。
如果需要访问引用页面的值,应该怎样做,谢谢各位大大!
谢谢指点,不过我在test.php赋值的变量是想在整个页面中都可以用得到。
如果在test1.php又重新赋值的话,就会重复了。而且有些变量两个文件里是有关联的。
如果分别赋值就不太好处理了。
这个不太清楚具体怎样用。我要使用的变量是一个从PHP assign过去的数组变量,这个可以吗?
不嵌入php文件,那从php文件assign过去的变量就是没有哦。
test.php
<?php
include("smarty_inc.php");
include("model.php");
$smarty->display("temp.html");
?> temp1.htm <html>
<head>
</head>
<body>
<b style="color:red;">{$sort} </b> <br/>
</body>
</html>
<?php
include("smarty_inc.php");
include("model.php");
$smarty->display("temp1.html");
?> temp.htm <html>
<head>
</head>
<body>
<b style="color:red;">{$sort} </b> <br/>
</body>
</html>
看看php手册。把引用文件的关系弄懂。
直接把数组赋值就行
比如
$arr=array(.........);
$smarty->assign('sort',$arr);
$smarty->display('temp.html');