0

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.

JSkirMan
  • 3
  • 1
  • 9

2 Answers2

0

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.

Irfan
  • 7,029
  • 3
  • 42
  • 57
  • I changed my model class name from InternetModelDefault to InternetModelInternet, also created a new model class page and keeped my default. Not sure if that's right ? – JSkirMan Jan 14 '13 at 13:37
  • Could you please give more info about path,class and file? – Irfan Jan 14 '13 at 13:40
  • i will add a PS of my mapstructure in the qeustion, the class it self only need to output "test". The component himself is a postalchecker for customers to show which packages we got in their region, handled by a JSON API. PrintScreen available in a min. – JSkirMan Jan 14 '13 at 13:46
  • hope this helps, img uploaded – JSkirMan Jan 14 '13 at 13:51
  • to push info from a controller to view i use assignref. Does a model also need a assign? – JSkirMan Jan 14 '13 at 14:05
  • @JSkirMan:Are you still getting error if not return the result from test function. – Irfan Jan 14 '13 at 14:08
  • instead of test() i used $this->test; and added a assignref in my model. This returns a NULL to my page, at least not an error, haha. But still not where i needed to be – JSkirMan Jan 14 '13 at 14:36
  • You can read this post-http://stackoverflow.com/questions/12929169/component-view-displaying-with-500-interval-server-error/12929925#12929925 – Irfan Jan 14 '13 at 14:39
0

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);
        }
}
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44