将变量从 PHP 传递给 Smarty [英] Passing variable from PHP to Smarty
本文介绍了将变量从 PHP 传递给 Smarty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个脚本,一个在 .php 中,一个在 .tpl 中我需要将 php 中的变量传递给 tpl.我试过这个,但没有任何效果(但不知何故
I had two script, one in .php and one in .tpl I need to pass the variable in php to the tpl. I tried this one, but nothinng works (but somehow
- 它可以工作一两天,然后,
- 显示空白,
- 如果我创建另一个 php 脚本 只是为了回显变量,它就可以工作.
- it works for one or two days, and after that,
- it showed blank,
- if i create another php script just to echo the variable, it works.
PHP 代码:
<?php
$usdidr2 = "12610.198648";
$usdidr2 = number_format($usdidr,2,',','.');
echo $usdidr2;
session_start();
$regValue = $usdidr2;
$_SESSION['regUSDIDR1'] = $regValue;
?>
智能代码:
<li>
<a href="example.php"><strong>
{php}
session_start();
$regValue = $_SESSION['regUSDIDR1'];
$regValue2 = number_format(45.99*$regValue,2,',','.');
echo "Rp. ".$regValue."";
print_r($regValue);
{/php}
</strong></a>
</li>
推荐答案
这里是从php发送数据到tpl的语法
Here is the syntax to send data from php to tpl
$smarty->assign('variable name with which you can access the data in tpl', $php_data_you_want_to_send);
更新:
$smarty->assign('rate',$usdidr2);// you just need to write rate without $
如果它是字符串,您可以像 {$rate}
一样使用 smarty 访问它你可以像 {$rate|print_r}
这样的 smarty 访问它,如果它是数组
You can access it in smarty like {$rate}
if it is string
You can access it in smarty like {$rate|print_r}
if it is array
这篇关于将变量从 PHP 传递给 Smarty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文