Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Joomla文章中的调用函数_Joomla_Joomla3.0 - Fatal编程技术网

Joomla文章中的调用函数

Joomla文章中的调用函数,joomla,joomla3.0,Joomla,Joomla3.0,我面临一个问题。我在Joomla administrator中创建了一篇文章,并在php文件中创建了一个函数。我必须在那篇文章中调用这个函数。我不知道如何调用本文中的函数。 代码如下: class modVodesbalanceHelper { function deductBalance() { $db = JFactory::getDBO(); $result = null; $user = JFactory::g

我面临一个问题。我在Joomla administrator中创建了一篇文章,并在php文件中创建了一个函数。我必须在那篇文章中调用这个函数。我不知道如何调用本文中的函数。 代码如下:

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 .
我将在joomla文章中添加php代码

检查要启用的sourcerer插件在此处检查插件启用状态:扩展->插件管理器->sourcerer

然后,在添加PHP脚本时,使用所见即所得编辑器底部的“插入代码”按钮。您的代码应该用

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

默认情况下,无法将PHP添加到Joomla文章中。为此,您需要使用第三方插件。就个人而言,我建议使用。安装并启用后,您可以在文章中使用以下内容:

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

不要在文章中包含PHP文件

如果您需要在Joomla文章中直接使用代码,请使用Sourcerer,如上述问题所示。如果您想将PHP代码保存在单独的模块中。使用 或模块。然后在Joomla的文章中,您可以这样放置代码

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