Developing an MVC Component/Developing a Basic Component: Difference between revisions
From Joomla! Documentation
Kevinkabatra (talk | contribs) m Fixed typo |
Kevinkabatra (talk | contribs) →How to add a component to Joomla!: Added information on why we include index.html files in every directory |
||
| Line 26: | Line 26: | ||
| 3 | | 3 | ||
| ''[[#index.html|site/index.html]]'' | | ''[[#index.html|site/index.html]]'' | ||
| | | prevents web server from listing directory content | ||
|- | |- | ||
| 4 | | 4 | ||
| ''[[#index.html|admin/index.html]]'' | | ''[[#index.html|admin/index.html]]'' | ||
| | | prevents web server from listing directory content | ||
|- | |- | ||
| 5 | | 5 | ||
| Line 38: | Line 38: | ||
| 6 | | 6 | ||
| ''[[#index.html|admin/sql/index.html]]'' | | ''[[#index.html|admin/sql/index.html]]'' | ||
| | | prevents web server from listing directory content | ||
|- | |- | ||
| 7 | | 7 | ||
| ''[[#index.html|admin/sql/updates/index.html]]'' | | ''[[#index.html|admin/sql/updates/index.html]]'' | ||
| | | prevents web server from listing directory content | ||
|- | |- | ||
| 8 | | 8 | ||
| ''[[#index.html|admin/sql/updates/mysql/index.html]]'' | | ''[[#index.html|admin/sql/updates/mysql/index.html]]'' | ||
| | | prevents web server from listing directory content | ||
|- | |- | ||
| 9 | | 9 | ||
Revision as of 15:19, 17 September 2015
Articles in This Series
- Introduction
- Developing a Basic Component
- Adding a View to the Site Part
- Adding a Menu Type to the Site Part
- Adding a Model to the Site Part
- Adding a Variable Request in the Menu Type
- Using the Database
- Basic Backend
- Adding Language Management
- Adding Backend Actions
- Adding Decorations to the Backend
- Adding Verifications
- Adding Categories
- Adding Configuration
- Adding ACL
- Adding an Install/Uninstall/Update Script File
- Adding a Frontend Form
- Adding an Image
- Adding a Map
- Adding AJAX
- Adding an Alias
- Using the Language Filter Facility
- Adding a Modal
- Adding Associations
- Adding Checkout
- Adding Ordering
- Adding Levels
- Adding Versioning
- Adding Tags
- Adding Access
- Adding a Batch Process
- Adding Cache
- Adding a Feed
- Adding an Update Server
- Adding Custom Fields
- Upgrading to Joomla4
This is a multiple-article series of tutorials on how to develop a Model-View-Controller Component for Joomla! Version
.
Begin with the Introduction, and navigate the articles in this series by using the navigation button at the bottom or the box to the right (the Articles in this series).
The first basic component
Let's create a Hello World! component.
Notes
- 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.
- You can follow the steps below to create the Hello World! component, or you can directly download the archive
How to add a component to Joomla!
To begin, you must first use your preferred file manager to create a directory for the Hello World! component. This directory can be anywhere on your file system, as long as it outside of your Joomla! installation directory. For this example we will name the directory com_helloworld, but this directory can be named anything.
Next, inside this directory we need to create some files. Using your preferred file manager, create the following files; as you create the files, add the source code for each file which is found in the File Details section.
| 1 | helloworld.xml | this is an XML (manifest) file that tells Joomla! how to install our component. |
| 2 | site/helloworld.php | this is the site entry point to the Hello World! component |
| 3 | site/index.html | prevents web server from listing directory content |
| 4 | admin/index.html | prevents web server from listing directory content |
| 5 | admin/helloworld.php | this is the administrator entry point to the Hello World! component |
| 6 | admin/sql/index.html | prevents web server from listing directory content |
| 7 | admin/sql/updates/index.html | prevents web server from listing directory content |
| 8 | admin/sql/updates/mysql/index.html | prevents web server from listing directory content |
| 9 | admin/sql/updates/mysql/0.0.1.sql |
Using your preferred file manager, create a .zip file of this directory. For this example we will name the file com_helloworld.zip, again this file could have been named anything.
Now we need to install the Hello World! component. There are two ways to do this, both are covered in Installing an Extension. Here we will cover the method using the Extension Manager of Joomla!.
- Using your preferred web browser, navigate to the Administrator panel of your Joomla! site. The address would be <yoursite>/joomla/administrator/index.php. For this example we will navigate to localhost/joomla/administrator/index.php.
- Click Extensions → Manage → Install → Upload Package File → Choose File
- Navigate and Select File
- Click Upload & Install
Note - You should see a message letting you know if the installation succeeded or failed.
You can test this basic function of the component by entering the Hello World! page for the site and administrator portions of your Joomla! website.
- Using your preferred web browser, navigate to the Hello World! component page located on the site portion of your website. The address would be <yoursite>/joomla/index.php?option=com_helloworld. For this example we will navigate to localhost/joomla/index.php?option=com_helloworld.
- Using your preferred web browser, navigate to the Hello World! component page located on the administrator portion of your website. The address would be <yoursite>/joomla/administrator/index.php?option=com_helloworld. For this example we will navigate to localhost/joomla/administrator/index.php?option=com_helloworld.
You can also notice that the Hello World! component is visible in the administrator site of your Joomla installation under the Components menu.
File Details
admin/sql/updates/mysql/0.0.1.sql is an empty file allowing to initialise schema version of the com_helloworld component.
helloworld.xml
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2.0" method="upgrade">
<name>Hello World!</name>
<!-- The following elements are optional and free of formatting constraints -->
<creationDate>December 2013</creationDate>
<author>John Doe</author>
<authorEmail>john.doe@example.org</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>
<update> <!-- Runs on update; New since J2.5 -->
<schemas>
<schemapath type="mysql">sql/updates/mysql</schemapath>
</schemas>
</update>
<!-- 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 link='index.php?option=com_helloworld'>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>
<!-- SQL files section -->
<folder>sql</folder>
</files>
</administration>
</extension>
site/helloworld.php
Hello World
admin/helloworld.php
Hello World administration
index.html
common to all folders
<html><body bgcolor="#FFFFFF"></body></html>
Contributors
Please create a pull request or issue at https://github.com/joomla/Joomla-3.2-Hello-World-Component for any code descprepancies or if editing any of the source code on this page.