> Please create a new models folder
/components/com_helloworld/models
> Please create <view>.php in the models folder
/components/com_helloworld/models/helloworld.php
> Please add this code in the file
<?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import Joomla modelitem library jimport('joomla.application.component.modelitem'); /** * HelloWorld Model */ class HelloWorldModelHelloWorld extends JModelItem { /** * @var string msg */ protected $msg; /** * Get the message * @return string The message to be displayed to the user */ public function getMsg() { if (!isset($this->msg)) { $this->msg = 'This message has been brought to you by the hello world model getMsg function.'; } return $this->msg; } }
> Please update your view.html.php file to call the getMsg() function
In the components/com_helloworld/views/helloworld/view.html.php we originally created the “Hello World” message via the following line
$this->msg = 'Hello World';
> The view.html.php file will be like below
<?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import Joomla view library jimport('joomla.application.component.view'); /** * HTML View class for the HelloWorld Component */ class HelloWorldViewHelloWorld extends JViewLegacy { // Overwriting JView display method function display($tpl = null) { // Assign data to the view $this->msg = $this->get('Msg'); // Display the view parent::display($tpl); } }