The HelloWorldViewHelloWorld class, in the view.html.php file, asks the model for data using the get method of the JViewLegacy.

For example, this get method converts the get('Msg') call into a getMsg() call on the model, which is the function which you have to provide in the model.

The model files are stored in the models folder, with the same name as the view.

site/models/helloworld.php

class HelloWorldModelHelloWorld extends JModelItem
{
protected $message;

public function getMsg()
{
if (!isset($this->message))
{
$this->message = 'Hello World!';
}

return $this->message;
}
}

site/views/helloworld/view.html.php

Now, instead of directly assigning the data to the view, use get method of JViewLegacy class to get data from the model.

class HelloWorldViewHelloWorld extends JViewLegacy
{
function display($tpl = null)
{
// Assign data to the view
$this->msg = $this->get('Msg');

// Check for errors.
if (count($errors = $this->get('Errors')))
{
JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');

return false;
}

// Display the view
parent::display($tpl);
}
}