Ho 在 Joomla Component 上调用变量项

Ho to call variables items on Joomla Component

我正在尝试在 Joomla 中创建我的第一个组件,但我不明白它是如何工作的:D

我用 "Component Creator" 创建了一个基本组件。 (我节省了很多时间...)。

现在,我的数据库中有一个 table,我将数据放在那里:

id = 1
name = Andrea 
note = Ciao

现在,我想使用 Joomla 语言从页面调用它。

在我的 models/component.php 我写道:

class Variabili extends JModelLegacy
{
    function estraivariabili()
    {
        $db =& JFactory::getDBO(); 

        $db->setQuery("SELECT * FROM #__table")->loadObjectList();

        return $value;
    }
}

在我的 default.php 上写了

$model=$this->Variabili();

//call the method
$items=$model->estraivariabili();

//print
print_r($items);

但是在页面上我有这个错误:

0 Call to undefined method Calcolo_imposteViewCalcoloonline::Variabili()

哪里错了?

因为我是初学者,请对我温柔点:D

提前致谢

安德里亚

你犯了一些错误。我已经重写了你的函数,这样你就可以得到它。一起来看看-

model,看起来还差不多吧。改成这样-

class Variabili extends JModelLegacy
{
    // Make the function public
    public function estraivariabili()
    {
        $db = &JFactory::getDBO(); 

        // Put the result into a variable first, then return it.
        $value = $db->setQuery("SELECT * FROM #__table")->loadObjectList();

        return $value;
    }
}

并且现在不从 default.php 调用 model 函数,而不是在 view.html.php 文件中编写代码。

首先在view.html.php文件的display函数中,使用getModel()函数获取model实例。

$model = $this->getModel();

现在您可以使用此 $model class 实例获取物品。

$this->items = $model->estraivariabili();

这将为您带来数据库中的数据table。您可以使用 default.php 文件中的数据。

只需尝试 default.php 文件-

print_r($this->items);