Difference between revisions of "Rvsjoen/tutorial/Developing an MVC Component/Part 01"
From Joomla! Documentation
|Line 6:||Line 6:|
Revision as of 16:31, 9 July 2011
Developing a Basic Component
Let's create a Hello World! component. All file name and path references in this tutorial are relative to the directory you are developing your extension in.
With your favorite editor, create a file site/helloworld.php containing the following text, yes, it is very simple but its purpose is simply to demonstrate where the entry point of the component is. After all, this is part 01. When Joomla! looks for a component it will look at the option variable given in the url, in our case this will be option=com_helloworld. This means that Joomla! will look in the components directory for a folder named com_helloworld and load the file helloworld.php contained within that directory.
You might at this point think to yourself, why are we creating a backend file when this part of the tutorial is only supposed to cover the frontend ? The answer to that question is simple, Joomla! will automatically create a menu item for your component in the backend "Components" menu when the component is installed, and there are no easy ways to avoid that. In order to not make that link point to a page not found, we will give it a file to point to.
With your favorite editor, create a file admin/helloworld.php containing the following text
In order for our extension to be recognized by Joomla! we also need to provide an installation xml file, also called the manifest. Open up helloworld.xml in your favorite editor and add the following piece of code.
<?xml version="1.0" encoding="utf-8"?> <extension type="component" version="1.7.0" method="upgrade"> <name>Hello World!</name> <!-- The following elements are optional and free of formatting constraints --> <creationDate>June 2011</creationDate> <author>John Doe</author> <authorEmail>email@example.com</authorEmail> <authorUrl>http://www.example.org</authorUrl> <copyright>Copyright Info</copyright> <license>License Info</license> <!-- The version string is recorded in the components table --> <version>0.0.1</version> <!-- The description is optional and defaults to the name --> <description>Description of the Hello World component ...</description> <!-- Site Main File Copy Section --> <!-- Note the folder attribute: This attribute describes the folder to copy FROM in the package to install therefore files copied in this section are copied from "site/" in the package --> <files folder="site"> <filename>index.html</filename> <filename>helloworld.php</filename> </files> <administration> <!-- Administration Menu Section --> <menu>Hello World!</menu> <!-- Administration Main File Copy Section --> <!-- Note the folder attribute: This attribute describes the folder to copy FROM in the package to install therefore files copied in this section are copied from "admin/" in the package --> <files folder="admin"> <!-- Admin Main File Copy Section --> <filename>index.html</filename> <filename>helloworld.php</filename> </files> </administration> </extension>
In order to stay in sync with the Joomla! conventions, and to not allow misconfigured web servers to allow directory listings in our component, we also need to add the following index.html file to every folder we create within our extension structure. The purpose of this file is to simply show a blank page if someone attempts to see the directory contents by using the absolute url.
Installing your extension
If you have used Joomla before reading this tutorial, you have noticed that extensions are installed using a compressed file containing all the things which are needed for installing and uninstalling them. Since Joomla! 1.6 you also have the option of putting the files in the correct places inside your Joomla! installation, and discovering it using the extension manager.
After installlation will notice that the Hello World component is visible in the administrator site of your Joomla! installation under the Components menu.
You can test this basic component by putting index.php?option=com_helloworld or administrator/index.php?option=com_helloworld in your browser address bar.
Packaging an installation zip file
Create a compressed file of your extension directory using the structure shown in the file listing section of this page or download the provided installable package.
When you have this package, install it using the extension manager.
Download this part
Articles in this series
This tutorial is supported by the following versions of Joomla!
- Part 01 - Developing a Basic Component
- Part 02 - Adding a view to the frontend
- Part 03 - Adding a menu item type to the frontend
- Part 04 - Adding a model to the frontend
- Part 05 - Adding options to menu items
- Part 06 - Using a database
- Part 07 - Basic backend
- Part 08 - Adding language translation
- Part 09 - Adding actions to backend
- Part 10 - Adding decorations to the backend
- Part 11 - Adding validation
- Part 12 - Adding categories
- Part 13 - Adding component options
- Part 14 - Adding ACL
- Part 15 - Adding a script file