我是第一次在Joomla中创建一个组件,现在我很难将模型中的数据调用到我的视图中。我这样做了如下:
//在我的模特中
class InternetModelDefault extends JModel {
public function test(){
$this->test='test';
}
}
//在我看来
class InternetViewInternet extends JView {
$model = $this->getModel();
$test = $model->test();
var_dump($test);
// Display the view
parent::display($tpl);
}
}
输出产生以下错误:
致命错误:在非对象中调用成员函数test() /var/websites/www.infrait.nl/content/components/com_internet/views/internet/view.html.php 在第66行
哪里出错了?请帮忙..
当前地图结构:
http://imgdump.nl/hosted/ad9e57de83060b3240f8fc6bba99237b.png
由于我是新手,我只能与您分享这个直接链接。
答案 0 :(得分:0)
您收到错误,因为未正确启动对象。将类名更改为InternetModelInternet
。模型文件名称为internet.php
。
如果它不起作用,请告诉我。
答案 1 :(得分:0)
你的model.php就像这样
jimport ('joomla.application.component.modellist');
class InternetModelInternet extends JModelList
{
public function test(){
$this->test='test';
}
}
并在view.html.php获取模型
jimport ('joomla.application.component.view');
class InternetViewInternet extends JView
{
public function display ($tpl = null)
{
$model = &$this->getModel ();
$test = $model->test();
var_dump($test);
// Display the view
parent::display($tpl);
}
}