Hello Guys,
I know there are a lot of Free Joomla Component out there, but what if what is out there is not exactly what you need?
This will be the first post in creating a simple Joomla Component.
In a Joomla Component there are 2 required files, first the scripting side and the html output side.
First were gonna tackle on the scripting side:
Lets make the name of our component "example".
If you are a Joomla / Mambo you can clearly see in the url the "option=com_componentname"
Then the files located are in the "/components/com_componentname/componentname.php" and "/components/com_componentname/componentname.html.php"
The "componentname.php" file is the scripting file where you usually execute database queries, variable manipulation etc.
The "componentname.html.php" file is where you usually display the result and add html tags so that you can manipulate the design of the output.
So we will first tackle the scripting side file.
so we need to create a folder inside "/components" named "com_example" and inside the com_example folder we create a php file called example.php.
Inside example.php:
defined( '_VALID_MOS' ) or die( 'Restricted access' );
// this is required so that we will have access on the browser in viewing this component, another Joomla security measure so that people wont accidentally see your pages.
require_once( $mainframe->getPath( 'front_html' ) );
//this line calls and loads the html side of the component.
switch($task){
//this line takes the task value in the url and chooses what function to execute.
default:
//this is chosen when the the task value is empty.
display_hello_world();
//calling the function
break;
//exists the switch function
}
function display_hello_world(){
$name = "Place Name Here";
//adding a name variable
HTML_example::hello_world($name);
//calling the function in html file and passing the variable name
//the HTML_example is the class name inside the html file, and the hello_world() is a function inside that class.
}
Next Post will discuss the html side so stay tuned...