在smarty文件中使用PHP函数

在smarty文件中使用PHP函数,php,function,smarty,Php,Function,Smarty,我在php中创建了以下函数。我想从smarty文件调用它,但我一直收到smarty的错误。我做错了什么 <?php function getCommission($inputid) { $database="xxxxxxxxxxxxxx"; mysql_connect (xxxxxxxxxxxxxxxxx); @mysql_select_db($database) or die( "Unable to select database"); $data = mys

我在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'];
 } 
}
 ?>

第三方物流代码的一部分是:

     {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>            
{include file=“getCommission”}
{$lang.convrate}
{$affiliate.conversion}%
{$lang.com}

我想你在上次获奖之前错过了一个括号:

"{getCommission($affiliate.id}"
首先需要使用Smarty,而不是使用
{include}

<?php
$smarty->registerPlugin("function","getCommission", "getCommission");

很抱歉我试图评论的编辑。现在,我在某个地方读到,我需要在smart.class.php文件中包含我的函数。除此之外,我也必须这样做吗?你也能描述一下如何调用这个函数吗?{getcommission}是否足够,因为我的函数有1个参数。我不知道您的代码结构,但在初始化smarty对象后调用
registerPlugin
。然后是的,该函数可以通过
{getCommission}
使用,就像通常的smarty函数一样。好的,谢谢你的帮助,我正在重新阅读smarty文档,试图解决这个问题。