您好,欢迎访问一九零五行业门户网

smarty 怎么调用 php类的常量成员

smarty 如何调用 php类的常量成员
php 内容:
username.'
';
echo $class_obj::pwd.'
';
$smarty->assign('class_obj', $class_obj);
$smarty->display('eg_4_2.tpl');
?>
tpl内容:
{$class_obj->username}
{$class_obj::pwd}
对于$class_obj->username
在 php 和 tpl 两边使用都正常。。。
对于$class_obj::pwd
在php使用就正常
在tpl使用就报错
请熟悉的指点下,谢谢!
------解决方案--------------------
您需要遵守 smarty 的规则,否则将被 smarty 开除
------解决方案--------------------
http://wenku.baidu.com/view/c2aa98ef551810a6f52486af.html
------解决方案--------------------
试下 my_class::pwd
还不行看这里
http://www.smarty.net/docs/en/advanced.features.static.classes.tpl
------解决方案--------------------
把类名传过去。$smarty->assign('my_class', my_class);
tpl调用:
{php}
echo my_class::pwd;
{/php}
php 5.3.0之后才可以用 $class_obj::pwd 调用。之前的版本是不能的。不知道你php版本是多少?
------解决方案--------------------
还在纠结啊,按我那种方法试了吗? 哪里不行?
------解决方案--------------------
不知道你在纠结什么:
php codeassign(a,$a); $smarty->assign(str1,$str1); $smarty->assign(str2,$str2); $smarty->display(test.html);?>
------解决方案--------------------
我是看明白了。但我无能为力。
------解决方案--------------------
$smarty->assign(str1,$str1);
 $smarty->assign(str2,$str2);
为测试数据,没用,删掉
------解决方案--------------------
理解你的需求, 很有可能smarty还没有收到这方面的需求,
所以也没有做出这个功能,你完全可以上他们的网站提下这个需求,
或者自己写个plugin

探讨
引用:
试下 my_class::pwd
还不行看这里
http://www.smarty.net/docs/en/advanced.features.static.classes.tpl
看了你给的链接
链接里讲的是 静态类
而我的问题是 类的静态成员。。。
还是要谢谢你们的回答。。。
------解决方案--------------------
这么无理的需求也提?开发的时候要变通
------解决方案--------------------
还在纠结这个问题吗?
{$class_obj::pwd}
被翻译成了
tpl_vars['class_obj']->value::pwd;?>
虽然
$class_obj = new my_class;
echo $class_obj->username.'
';
echo $class_obj::pwd.'
';
可以得到正确的结果(但他是不严密的)
但这样呢?
$class_obj->x = new my_class;
echo $class_obj->x->username.'
'; //这里能输出 深空
echo $class_obj->x::pwd.'
';//这里就要报错了:
parse error: syntax error, unexpected t_paamayim_nekudotayim, expecting ',' or ';' in
------解决方案--------------------
我查过手册,只有变量可以那样传值,常量不能这样传值!!
只能这样:
php:$pwd=$class_obj::pwd; $smarty->assign(pwd,$pwd);
tpl:{$pwd}
------解决方案--------------------
其它类似信息

推荐信息