【发布时间】:2018-07-18 10:51:01
【问题描述】:
我有一个 smarty 项目,在 php 文件中,我设置了一个 abc 变量:
$smarty->assign('abc', '123');
现在我可以在其对应的.tpl 文件中使用{$abc}。
但是现在我可以在 php 文件中使用abc 吗?
我试过$smarty->abc和$smarty->$abc都无法访问。
EDIT-01
如果我使用
$smarty->assign('abc', '1234');
$abc2 = $smarty->get_template_vars('abc');
我会得到以下错误:
Fatal error: Uncaught Error: Using $this when not in object context in /Users/sof3/Desktop/smarty-test02/php/test.php:36 Stack trace: #0 {main} thrown in /Users/sof3/Desktop/smarty-test02/php/test.php on line 36
【问题讨论】:
-
您可以使用
get_template_vars()函数并像这样访问变量$abc = $this->get_template_vars('abc'); -
@Bhavin 兄弟,看看我的 eidt-01。
-
你有
assign()-ed 东西给$this吗?我不这么认为。您可以通过调用$smarty对象的assign()方法让Smarty 知道abc。使用$smarty->get_template_vars('abc')取回值。 -
致命错误:未捕获 --> Smarty:未定义扩展类 'Smarty_Internal_Method_Get_Template_Vars'
-
是的,sof-03。 @axiac 是对的 这是我的错字使用
$smarty->get_template_vars('abc')像这样。