Compoent Part 1: ' - JEXEC' 'Restricted Access' 'Task' 'Name' 'John'
Compoent Part 1: ' - JEXEC' 'Restricted Access' 'Task' 'Name' 'John'
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
switch ($task) {
case 'show':
default:
echo 'Hello ' . $name . ' in our World!';
break;
}
?>
You may have asked yourself ‘Whats the JRequest::getVar() for? And whats it
doing with that variable?’. To make Joomla more secure, all global variables
should be read through this function. It removes the possibility for code
injection and/or SQL injection. You can also define a default value (as you can
see in line 6).
In Joomla! the variable ‘task’ is commonly used to switch between different, you
might guess it, tasks. Besides that, there is the variable ‘option’, whose value is
used to determine which component is supposed to be loaded. So never use it for
anything else, otherwise you might get funny errors.
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
switch ($task) {
case 'show':
default:
hello_HTML::show( $name );
break;
}
?>
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
class hello_HTML {
}
?>
/**
* Hello Model for Hello World Component
*
* @package Joomla.Tutorials
* @subpackage Components
* @link http://dev.joomla.org/component/option,com_jd-
wiki/Itemid,31/id,tutorials:modules/
* @license GNU/GPL
*/
jimport( 'joomla.application.component.model' );
/**
* Hello Model
*
* @package Joomla.Tutorials
* @subpackage Components
*/
class HelloModelHello extends JModel
{
/**
* Gets the greeting
* @return string The greeting to be displayed to the user
*/
function getGreeting()
{
return 'Hello, World!';
}
}
You will notice a line that starts with jimport. The jimport function is used to
load files from the Joomla! framework that are required for our component. This
particular statement will load the file
/libraries/joomla/application/component/model.php. The ‘.’s are used as
directory separators and the last part is the name of the file to load. All files are
loaded relative to the libraries directory. This particular file contains the class
definition for the JModel class, which is necessary because our model extends
this class.