2014-10-16 62 views
2

我正面臨一個問題。我在Joomla管理員中創建了一篇文章,並且我已經在php文件中創建了一個函數。我必須在那篇文章中調用這個函數。我不知道如何在文章中調用函數。 下面是代碼:Joomla文章裏面的調用函數

class modVodesbalanceHelper { 
function deductBalance() 
    { 
     $db  = JFactory::getDBO(); 
     $result = null; 

     $user = JFactory::getUser(); 
     if ($user->guest) { 
      return false; 
     } 

     $query = 'SELECT credit' . 
       ' FROM #__vodes_credits' . 
       ' WHERE userid = ' . (int) $user->id 
       ; 
     $db->setQuery($query); 
     $result = $db->loadResult(); 

     $result_final=$result-10; 


$query = 'update #__vodes_credits SET credit='.$result_final. 
       ' WHERE userid = ' . (int) $user->id 
       ; 
//echo $query; 
$db->setQuery($query); 


     $result = $db->loadResult(); 

    } 
    } 

In admin panel, in article i have write this code: 
<script> 
window.onload=function() 
{ 
var a=confirm("do you want to purchase this credit"); 
if(a) 
{ 
document.location.href ="index.php?option=com_content&view=featured"; 
} 
else 
{ 
document.location.href="index.php?option=com_content&view=article&id=3"; 
} 
} 
</script> 
I have to call deductBalance when user click on the "OK" of comfirm box. 
Please tell me to sought it . 

回答

0

我會用Sourcerer添加的Joomla文章內的PHP代碼。

檢查要啓用的sourcerer插件(檢查插件啓用狀態在這裏:extensions-> plugin manager-> sourcerer)。

然後,在添加PHP腳本時,使用WYSIWYG編輯器底部的"Insert Code"按鈕。你的代碼應該用

{source} 
//php code wrapped by <?php ?> 
{/source} 
0

默認情況下,你不能將PHP添加到Joomla文章中。爲此,您需要使用第三方插件。我個人建議使用Sourcerer。一旦安裝並啓用,您可以使用您的文章如下:

{source} 
<?php 
    // All your PHP code 
?> 
{/source} 

如果需要使用代碼直接在文章的Joomla然後使用源碼人員在上面不包括你的文章

0

內PHP文件的問題。如果您覺得將PHP代碼保存在單獨的模塊中。使用Blank Modulemod_php模塊。然後在你的Joomla文章中,你可以像這樣放置代碼,

{loadposition}*Your Custom Module Position*{/loadposition}