Actions

User

Difference between revisions of "Rvsjoen/tutorial/Developing an MVC Component/Part 01"

From Joomla! Documentation

< User:Rvsjoen‎ | tutorial/Developing an MVC Component
(Installing your extension)
(Developing a Basic Component)
Line 1: Line 1:
 
= Developing a Basic Component =
 
= Developing a Basic Component =
Let's create a ''Hello World!'' 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.
  
=== Public display ===
+
=== Basic frontend ===
With your favorite file manager and editor, create a file ''yoursite/components/com_helloworld/helloworld.php'' containing
+
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.
 +
 
 +
<span id="site/helloworld.php">
 +
''site/helloworld.php''
 
<source lang="php">
 
<source lang="php">
Hello world
+
Hello World
 
</source>
 
</source>
 +
</span>
  
You can test this basic component by putting ''index.php?option=com_helloworld'' in your browser address (don't forget to prefix this address with your Joomla!1.6 installation path) after installing this component.
+
=== Basic backend ===
  
=== Administrator management ===
+
With your favorite editor, create a file ''admin/helloworld.php'' containing the following text
With your favorite file manager and editor, create a file ''yoursite/administrator/components/com_helloworld/helloworld.php'' containing
+
 
<source lang="php" line>
+
<span id="admin/helloworld.php">
Hello world administration
+
''admin/helloworld.php''
 +
<source lang="php">
 +
Hello Admins
 
</source>
 
</source>
 +
</span>
  
You can test this basic component by putting ''administrator/index.php?option=com_helloworld'' in your browser address after installing the component.
+
=== Installation manifest ===
  
=== Packaging an installation zip file ===
+
In order for our extension to be recognized by Joomla! we also need to provide an installation xml file, also called the manifest.
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.
+
Open up ''helloworld.xml'' in your favorite editor and add the following piece of code.
  
 
+
<span id="helloworld.xml">''helloworld.xml''
With your favorite file manager, create a directory (outside your Joomla!1.6 installation directory) containing
+
* ''[[#helloworld.xml|helloworld.xml]]''
+
* ''[[#site/helloworld.php|site/helloworld.php]]''
+
* ''[[#index.html|site/index.html]]''
+
* ''[[#index.html|admin/index.html]]''
+
* ''[[#admin/helloworld.php|admin/helloworld.php]]''
+
* ''[[#index.html|admin/sql/index.html]]''
+
* ''[[#index.html|admin/sql/updates/index.html]]''
+
* ''[[#index.html|admin/sql/updates/mysql/index.html]]''
+
* ''[[#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''
+
 
+
Create a compressed file of this directory or directly download the [http://joomlacode.org/gf/download/frsrelease/11394/58225/com_helloworld-1.6-part01.zip archive] and install it using the extension manager of Joomla!1.6. You can test this basic component by putting ''index.php?option=com_helloworld'' or ''administrator/index.php?option=com_helloworld'' in your browser address. You can also notice that the ''Hello World!'' component is visible in the administrator site of your Joomla!1.6 installation under the ''Components'' menu.
+
 
+
<span id="helloworld.xml">
+
''helloworld.xml''
+
 
<source lang="xml">
 
<source lang="xml">
 
<?xml version="1.0" encoding="utf-8"?>
 
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="1.6.0" method="upgrade">
+
<extension type="component" version="1.7.0" method="upgrade">
  
 
<name>Hello World!</name>
 
<name>Hello World!</name>
 
<!-- The following elements are optional and free of formatting constraints -->
 
<!-- The following elements are optional and free of formatting constraints -->
<creationDate>November 2009</creationDate>
+
<creationDate>June 2011</creationDate>
 
<author>John Doe</author>
 
<author>John Doe</author>
 
<authorEmail>john.doe@example.org</authorEmail>
 
<authorEmail>john.doe@example.org</authorEmail>
Line 53: Line 45:
 
<!-- The description is optional and defaults to the name -->
 
<!-- The description is optional and defaults to the name -->
 
<description>Description of the Hello World component ...</description>
 
<description>Description of the Hello World component ...</description>
 
<update> <!-- Runs on update; New in 1.6 -->
 
<schemas>
 
<schemapath type="mysql">sql/updates/mysql</schemapath>
 
</schemas>
 
</update>
 
  
 
<!-- Site Main File Copy Section -->
 
<!-- Site Main File Copy Section -->
 
<!-- Note the folder attribute: This attribute describes the folder
 
<!-- Note the folder attribute: This attribute describes the folder
 
to copy FROM in the package to install therefore files copied
 
to copy FROM in the package to install therefore files copied
in this section are copied from /site/ in the package -->
+
in this section are copied from "site/" in the package -->
 
<files folder="site">
 
<files folder="site">
 
<filename>index.html</filename>
 
<filename>index.html</filename>
Line 75: Line 61:
 
<!-- Note the folder attribute: This attribute describes the folder
 
<!-- Note the folder attribute: This attribute describes the folder
 
to copy FROM in the package to install therefore files copied
 
to copy FROM in the package to install therefore files copied
in this section are copied from /admin/ in the package -->
+
in this section are copied from "admin/" in the package -->
 
<files folder="admin">
 
<files folder="admin">
 
<!-- Admin Main File Copy Section -->
 
<!-- Admin Main File Copy Section -->
 
<filename>index.html</filename>
 
<filename>index.html</filename>
 
<filename>helloworld.php</filename>
 
<filename>helloworld.php</filename>
<!-- SQL files section -->
 
<folder>sql</folder>
 
 
</files>
 
</files>
 
</administration>
 
</administration>
Line 89: Line 73:
 
</span>
 
</span>
  
<span id="site/helloworld.php">
+
=== Additional files ===
''site/helloworld.php''
+
<source lang="php">
+
Hello World
+
</source>
+
</span>
+
  
<span id="admin/helloworld.php">
+
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.
''admin/helloworld.php''
+
<source lang="php">
+
Hello World administration
+
</source>
+
</span>
+
  
 
<span id="index.html">
 
<span id="index.html">
''index.html'' common to all folders
+
''index.html''
 
<source lang="html4strict">
 
<source lang="html4strict">
<html><body bgcolor="#FFFFFF"></body></html>
+
<!DOCTYPE html><title></title>
 
</source>
 
</source>
 
</span>
 
</span>
 
  
 
== Installing your extension ==
 
== Installing your extension ==

Revision as of 17:06, 9 July 2011

Contents

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.

Basic frontend

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.

site/helloworld.php

Hello World

Basic backend

With your favorite editor, create a file admin/helloworld.php containing the following text

admin/helloworld.php

Hello Admins

Installation manifest

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.

helloworld.xml

<?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>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>
 
        <!-- 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>

Additional files

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.

index.html

<!DOCTYPE html><title></title>

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.

File listing

Download this part

com_helloworld-part01.zip

Articles in this series

This tutorial is supported by the following versions of Joomla!

Joomla 2.5