-
Notifications
You must be signed in to change notification settings - Fork 30
004. Adding a model to the site part
Now, we want to create a view on the front end.
Newly created files
components/com_foos/Model/FooModel.php
Modified files
administrator/components/com_foos/foos.xml
components/com_foos/View/Foo/HtmlView.php
components/com_foos/tmpl/foo/default.php
https://github.com/astridx/boilerplate/compare/t3...t4
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;
}
}
We need to modify our installation XML file, the update server and the change log to include the new version.
administrator/components/com_foos/foos.xml
components/com_foos/View/Foo/HtmlView.php
components/com_foos/tmpl/foo/default.php
Omitting the closing tag at the end of a file is just one solution for avoiding blanks and other characters at the end of file. For example any char which is accidentally added behind the closing tag would trigger an error when trying to modify header info later.
Removing the closing tag is kind of "good practice" referring to many coding guidelines.
It is important to know: Every time you press return
on your keyboard you're actually inserting an invisible character
called a line ending.
Historically, different operating systems have handled line endings differently.
Because utilities that are supposed to operate on files may not cope well with lines that don't end with a newline. Sometimes, lines not ending in a newline character aren't considered actual lines. Which means: if your last line is a line of code, it might be ignored by those tools.
An argument can also be made for cleaner diffs.
Changing:
...
defined('_JEXEC') or die;
?>
Hello Foos (invisible character)
to:
...
defined('_JEXEC') or die;
?>
Hello Foos
(invisible character)
involves only a one-line change in the diff:
...
defined('_JEXEC') or die;
?>
Hello Foos
+<?php macheEtwas()
(invisible character)
This beats the more confusing multi-line diff when the trailing comma was omitted:
defined('_JEXEC') or die;
?>
-Hello Foos (invisible character)
+Hello Foos
+<?php macheEtwas()(invisible character)