简体   繁体   English

joomla 3.2模块helper.php

[英]joomla 3.2 module helper.php

I'm doing a module for joomla 3.2,I'm trying to pass a variable from one function to another in the same class, the purpose is to use it in a query. 我正在为joomla 3.2做一个模块,我正在尝试将变量从一个函数传递到同一类中的另一个函数,目的是在查询中使用它。

How can I pass the "$result" variable in the query of the function due() ? 如何在函数Due()的查询中传递“ $ result”变量?

<?php
class modUno
{     
    public static function Uno()
    {   
        $db = JFactory::getDBO();   
        $query = "SELECT id AS memTotal FROM #__users WHERE username = 'bruno';";

        $db->setQuery($query);
        $result = $db->query();
        return $result->fetch_object()->memTotal;
    }

    public static function due()
    {
        $result->due();

        $db = JFactory::getDBO();   
        $query = "SELECT avatar AS memTotal FROM #__comprofiler WHERE id = '$result';";

        $db->setQuery($query);
        $resulta = $db->query();
        return $resulta->fetch_object()->memTotal;
    }
}
?>

above is the "helper.php", then there's the "mod_chat.php", finally, there is "default.php" 上面是“ helper.php”,然后是“ mod_chat.php”,最后是“ default.php”

mod_chat mod_chat

enter code here

<?php

defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( dirname(__FILE__).'/helper.php' );

$risultato = modUno::uno();
$foto = modUno::due();
require JModuleHelper::getLayoutPath('mod_chat');
?>

default.php default.php

enter code here


<?php defined( '_JEXEC' ) or die( 'Restricted access' ); ?>

<p> risultato: <?php echo $risultato; ?></p>
<p> foto:<img src="http://somesite.com/images/comprofiler/<?php echo $foto; ?>" /></p>

returns errors ! 返回错误!

Firstly, this is a PHP question, not a Joomla question. 首先,这是一个PHP问题,而不是Joomla问题。 I've found the PHP tutorial on codeacademy.com to be an excellent resource for learning PHP. 我发现codeacademy.com上的PHP教程是学习PHP的绝佳资源。

Looks like you are trying to get a user's Community Builder avatar. 看来您正在尝试获取用户的Community Builder头像。 You should not be using direct database queries here. 您不应在此处使用直接数据库查询。 Use Community Builder data API to get what you need. 使用Community Builder数据API来获取所需的信息。 Read more about it here - https://www.joomlapolis.com/support/tutorials/120-api-usage/18361-obtaining-field-values-through-getfields-api (see the end of this article, the code for getting avatar is there) 在此处了解更多信息-https: //www.joomlapolis.com/support/tutorials/120-api-usage/18361-obtaining-field-values-through-getfields-api (请参阅本文末尾的代码)有化身在那里)

If you wish to absolutely query the DB, rather than 2 different functions, you should make just 1 and use a JOIN to get the user's avatar based on his Joomla username. 如果您要绝对查询数据库,而不是2个不同的函数,则应只设置1个并使用JOIN根据用户的Joomla用户名获取其化身。

<?php
class modUno
{     
    public static function avatar()
    {   
        $db = JFactory::getDBO();   
        $query = "SELECT cb.avatar FROM #__comprofiler AS cb, #__users AS u 
        WHERE u.id=cb.user_id AND u.username = 'bruno'";

        $db->setQuery($query);
        $result = $db->loadResult();
        return $result;
        //return $result->fetch_object()->memTotal;
    }
}     

@Lodder - You should never be directly calling execute() when using select queries with Joomla. @Lodder-在Joomla中使用选择查询时,永远不要直接调用execute()。

As a side note - you need to use ModUno::due() instead of $result->due() 附带说明-您需要使用ModUno :: due()而不是$ result-> due()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 joomla 1.7:覆盖模块helper.php - joomla 1.7 : override a module helper.php Joomla 模块 – 如何将表单数据发送到 helper.php 中的 function - Joomla Module – How to send formdata to a function in helper.php helper.php中的JText字符串 - JText string in helper.php 将变量传递给helper.php - Pass variable to helper.php 使用代码接收Laravel未检测到helper.php上的功能 - Function on helper.php not detected with codeception Laravel /modules/mod_feed/helper.php中的错误 - error in /modules/mod_feed/helper.php Composer:自动加载文件 helper.php 是自动加载的,但其中的函数不是 - Composer: Autoloaded file helper.php is autoloaded but the functions inside it are not 如何在 Laravel Helper 函数中设置和获取 Cookie。 函数在 App/Http/Helper.php - How to Set And Get Cookies in laravel Helper function. Function is in App/Http/Helper.php PHP 致命错误:未捕获错误:Class 'Normalizer' not found in /usr/share/php/Symfony/Component/Console/Helper/Helper.ZE1BFD762321E409963CEE4AC0B6ECZ8 - PHP Fatal error: Uncaught Error: Class 'Normalizer' not found in /usr/share/php/Symfony/Component/Console/Helper/Helper.php 调用未定义的函数,更改helper.php文件,但仍无法调用presentPrice函数 - Call to undefined function, changes on helper.php file but still cant call presentPrice function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM