How to add the default Model to your Joomla 3 component?

> 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); } }

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Enable Two Factor Authentication in Joomla 3.5?

> Please login to Joomla admin dashboard > You will have a notification, please click on...

How to Change an Article Category in Joomla 3.5?

> Please login to your Joomla 3.5 Admin Dashboard > Please go to Content > click...

How to Create a New Category in Joomla 3.5?

> Please login to Joomla 3.5 Admin Dashboard > Please click on the Content > Catagory...

How to Create a New Article in Joomla 3.5?

> Please login to your Joomla 3.5 Admin Dashboard > Please Click Content > Articles...

How to Log in to your Joomla 3.5 Dashboard?

> Please navigate your site with "/administrator", for e.g. domain.com/administrator >...

Powered by WHMCompleteSolution