smarty 如何调用 php类的常量成员
php 内容:
require("libs/Smarty.class.php");
class my_class
{
const PWD = "gogo";
var $username = "深空";
}
$class_obj = new my_class;
echo $class_obj->username.'
';
echo $class_obj::PWD.'
';
$smarty->assign('class_obj', $class_obj);
$smarty->display('eg_4_2.tpl');
?>
tpl内容:
<?php class C{
const AAA = "This is const<br>";
}
$obj = new C();
$a = C::AAA;
$smarty->assign("A",$a);
$smarty->assign("str1",$str1);
$smarty->assign("str2",$str2);
$smarty->display("test.html");
?>
<br><font color="#e78608">------解决方案--------------------</font><br>我是看明白了。但我无能为力。
<br><font color="#e78608">------解决方案--------------------</font><br> $smarty->assign("str1",$str1);<br> $smarty->assign("str2",$str2);<br>为测试数据,没用,删掉
<br><font color="#e78608">------解决方案--------------------</font><br>理解你的需求, 很有可能smarty还没有收到这方面的需求,<br>所以也没有做出这个功能,你完全可以上他们的网站提下这个需求,<br>或者自己写个plugin<br><br>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号