|
Sep 10
Joomla custom component tutorial - Part 1 |
|
|
How to create custom Joomla components
A. The Basics
This article requires PHP knowledge and some basic knowledge of the Joomla paradigm.
We will name our component “mycomponent”
First we must understand how Joomla makes the call to a component. Since Joomla is a one entry point framework, all calls go through index.php. the “option” parameter indicates what component gets called.
In order for Joomla to find the component, there must be a folder called “com_mycomponent”, and the main component file should be called mycomponent.php
*Mind the case sensitivity of LINUX based hostings*
Joomla will give control to your component, and the output will be displayed in the template you set up in your site.
Common practice is to use the “task” parameter to indicate witch action should the component do. Joomla reads as a standard this parameter. You can rely on it that $task, $option and $Itemid (will be discussed later) are initialized before the entry into the component
So for the first step just create a folder /components/com_ mycomponent
Create the file /components/com_ mycomponent/mycomponent.php
And write this in it:
switch ($task) {
default:
case 'hello':
echo 'Hello World!';
break;
case 'bye':
echo 'Good Bye World!';
break;
}
?>
So if you now call you component in you browser with the task set to “hello” then you will get the “Hello World” in the content area , and with Task “bye” you will get a “Good Bye World” .
So we got a first running component.
B. Administration Backend
Most components have also administration options – mostly configurations or statistics. Some get the needed data in admin, some have just a configuration. Regardless, question is how it’s done.
All admin tasks will be processed through a file in /administrator/components/com_ mycomponent that you have to name admin.mycomponent.php
|
|
|