[英]Use PHP function in a smarty file
我在php中創建了以下函數。 我想從一個smarty文件中調用它,但是我一直從smarty中得到一個錯誤。 我究竟做錯了什么?
<?php
function getCommission($inputid)
{
$database="xxxxxxxxxxxxxx";
mysql_connect (xxxxxxxxxxxxxxxxx);
@mysql_select_db($database) or die( "Unable to select database");
$data = mysql_query("SELECT * FROM hb_aff WHERE id = $inputid")
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
return $info['total_commissions'];
}
}
?>
tpl代碼的一部分是:
{include file="getCommission"}
<tr>
<td >{$lang.convrate}</td>
<td >{$affiliate.conversion} %</td>
<td >{$lang.commissions}</td>
<td ><input size="3" value="{getCommission($affiliate.id}" name="total_commissions"/></td>
</tr>
我想您在最后一次贊美之前錯過了這里的括號:
"{getCommission($affiliate.id}"
您首先需要向Smarty 注冊該功能 ,而不是使用{include}
:
<?php
$smarty->registerPlugin("function","getCommission", "getCommission");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.