Reputation: 3
I am creating a component in Joomla for the first time, now i am having a hard time calling data from my model in to my view. I did this as follows:
//In my model
class InternetModelDefault extends JModel {
public function test(){
$this->test='test';
}
}
//In my view
class InternetViewInternet extends JView {
$model = $this->getModel();
$test = $model->test();
var_dump($test);
// Display the view
parent::display($tpl);
}
}
The output gives the following error:
Fatal error: Call to a member function test() on a non-object in /var/websites/www.infrait.nl/content/components/com_internet/views/internet/view.html.php on line 66
Where does it went wrong? Please some help..
Current mapstructure:
http://imgdump.nl/hosted/ad9e57de83060b3240f8fc6bba99237b.png
As i am new i can only share you this direct link.
Upvotes: 0
Views: 2593
Reputation: 13728
your model.php like this
jimport ('joomla.application.component.modellist');
class InternetModelInternet extends JModelList
{
public function test(){
$this->test='test';
}
}
and in view.html.php get model
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);
}
}
Upvotes: 0
Reputation: 7059
You are getting the error because object is not initiated properly.Change class name to InternetModelInternet
. And model file name will be internet.php
.
Let me know if it does not work.
Upvotes: 0