Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

004. Adding a model to the site part

Astrid edited this page Oct 17, 2019 · 16 revisions

In this chapter we will ...

Now, we want to create a view on the front end.

t4_1

Newly created or Modified files

Newly created files

components/com_foos/Model/FooModel.php

Modified files

changelog.xml

foo_update.xml

administrator/components/com_foos/foos.xml

components/com_foos/View/Foo/HtmlView.php

components/com_foos/tmpl/foo/default.php

All changes at a glance

https://github.com/astridx/boilerplate/compare/t3...t4

Detailed explanations

File Structure

Newly created files

components/com_foos/Model/FooModel.php

<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_foos
 *
 * @copyright   Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
namespace Joomla\Component\Foos\Site\Model;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
/**
 * Foo model for the Joomla Foos component.
 *
 * @since  1.0.0
 */
class FooModel extends BaseDatabaseModel
{
	/**
	 * @var string message
	 */
	protected $message;
	/**
	 * Get the message
	 *
	 * @return  string  The message to be displayed to the user
	 */
	public function getMsg()
	{
		if (!isset($this->message))
		{
			$this->message = 'Hello Foo!';
		}
		return $this->message;
	}
}

Modified files

changelog.xml

Comparing t3 t4 · astridx boilerplate(5)

foo_update.xml

Comparing t3 t4 · astridx boilerplate(3)

administrator/components/com_foos/foos.xml

Comparing t3 t4 · astridx boilerplate(2)

components/com_foos/View/Foo/HtmlView.php

Comparing t3 t4 · astridx boilerplate(1)

components/com_foos/tmpl/foo/default.php

Comparing t3 t4 · astridx boilerplate

Example in Joomla 4

Side Note

Test your component

Concluding Remark

Overview of all files