Archived

Difference between revisions of "Developing a MVC Component/Developing a Basic Component"

From Joomla! Documentation

< Archived:Developing a MVC Component
m (Reverted edits by Mạnh Tiến (talk) to last revision by Tom Hutchison)
(75 intermediate revisions by 18 users not shown)
Line 1: Line 1:
{{underconstruction}}
+
{{version/tutor|2.5}}
== Articles in this series ==
+
{{Chunk:Developing a Model-View-Controller (MVC) Component for Joomla!2.5 - Contents}}
[[Developing a Model-View-Controller (MVC) Component for Joomla!1.6 - Part 01]]
 
 
 
[[Developing a Model-View-Controller (MVC) Component for Joomla!1.6 - Part 02]]
 
 
 
== Introduction ==
 
This tutorial is part of the [[Developing a Model-View-Controller (MVC) Component for Joomla!1.6]] tutorial.
 
  
 +
This tutorial is part of the [[Developing a Model-View-Controller (MVC) Component for Joomla!2.5]] tutorial.
 
== The first basic component ==
 
== The first basic component ==
 
Let's create a ''Hello World!'' component.
 
Let's create a ''Hello World!'' component.
 
=== Public display ===
 
=== Public display ===
With your favorite file manager and editor, create a file ''components/com_helloworld/helloworld.php'' containing  
+
With your favorite file manager and editor, create a file ''yoursite/components/com_helloworld/helloworld.php'' containing  
 
<source lang="php">
 
<source lang="php">
 
Hello world
 
Hello world
 
</source>
 
</source>
  
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).
+
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!2.5 installation path) after installing this component.
  
 
=== Administrator management ===
 
=== Administrator management ===
With your favorite file manager and editor, create a file ''administrator/components/com_helloworld/helloworld.php'' containing  
+
With your favorite file manager and editor, create a file ''yoursite/administrator/components/com_helloworld/helloworld.php'' containing  
 
<source lang="php">
 
<source lang="php">
 
Hello world administration
 
Hello world administration
 
</source>
 
</source>
  
You can test this basic component by putting ''administrator/index.php?option=com_helloworld'' in your browser address.
+
You can test this basic component by putting ''administrator/index.php?option=com_helloworld'' in your browser address after installing the component.
  
 
=== Packaging an installation zip file ===
 
=== Packaging an installation zip file ===
 
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.
 
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.
  
Delete the ''components/com_helloworld'' and ''administrator/components/com_helloworld'' directories of your Joomla!1.6 installation.
+
With your favorite file manager, create a directory (outside your Joomla installation directory) containing
 
 
With your favorite file manager, create a directory (outside your Joomla!1.6 installation directory) containing
 
 
* ''[[#helloworld.xml|helloworld.xml]]''
 
* ''[[#helloworld.xml|helloworld.xml]]''
 
* ''[[#site/helloworld.php|site/helloworld.php]]''
 
* ''[[#site/helloworld.php|site/helloworld.php]]''
 
* ''[[#index.html|site/index.html]]''
 
* ''[[#index.html|site/index.html]]''
 +
* ''[[#index.html|admin/index.html]]''
 
* ''[[#admin/helloworld.php|admin/helloworld.php]]''
 
* ''[[#admin/helloworld.php|admin/helloworld.php]]''
* ''[[#index.html|admin/index.html]]''
+
* ''[[#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]]''
 +
 
 +
''admin/sql/updates/mysql/0.0.1.sql'' is an empty file allowing to initialise schema version of the com_helloworld component.
 +
 
 +
<span id="admin/sql/updates/mysql/0.0.1.sql">
 +
''admin/sql/updates/mysql/0.0.1.sql''
 +
<source lang="sql">
 +
</source>
 +
</span>
 +
 
 +
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. 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 installation under the ''Components'' menu.
  
Create a compressed file of this directory or directly download the [http://joomlacode.org/gf/project/helloworld_1_6/scmsvn/?action=browse&path=%2F%2Acheckout%2A%2Ftrunk%2Fcom_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.
+
Note: '''<name>Hello World!</name>''' is tricking you into thinking that this is actually only a name, and you could call it 'fluffy' or 'bippo', but this is not true. As far as I understand the name in between the tags is getting automagically lowercased, white spaces and special characters are removed (the ! for example) and joomla starts to look for files/folders responding to this name. So the name you are giving there is actually very crucial for your component to work. In other words, if you would change "Hello World!" to "helloworld" everyhting would still work. If you would change it to "helloworld2" the component would be looking for different folders and file names.
  
 
<span id="helloworld.xml">
 
<span id="helloworld.xml">
Line 44: Line 51:
 
<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="2.5.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 -->
Line 57: Line 65:
 
<!-- 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 2.5 -->
 +
<schemas>
 +
<schemapath type="mysql">sql/updates/mysql</schemapath>
 +
</schemas>
 +
</update>
  
 
<!-- Site Main File Copy Section -->
 
<!-- Site Main File Copy Section -->
Line 75: Line 89:
 
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">
<!-- Site 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>
</files>
+
<!-- SQL files section -->
 +
<folder>sql</folder>
 +
</files>
 
</administration>
 
</administration>
 +
 
</extension>
 
</extension>
 
</source>
 
</source>
Line 99: Line 116:
  
 
<span id="index.html">
 
<span id="index.html">
''index.html''
+
''index.html'' common to all folders
 
<source lang="html4strict">
 
<source lang="html4strict">
 
<html><body bgcolor="#FFFFFF"></body></html>
 
<html><body bgcolor="#FFFFFF"></body></html>
 
</source>
 
</source>
 
</span>
 
</span>
 +
 +
== Navigate ==
 +
 +
[[J2.5:Developing_a_MVC_Component/Adding_a_view_to_the_site_part|Next: Adding a view to the site part]]
  
 
== Contributors ==
 
== Contributors ==
 
*[[User:cdemko|Christophe Demko]]
 
*[[User:cdemko|Christophe Demko]]
 +
*[[User:oaksu|Ozgur Aksu]]
  
[[Category:Development]]
+
[[Category:Component Development]]
[[category:Joomla! 1.6]]
+
[[Category:Joomla! 1.6]]
[[category:Manual]]
+
[[Category:Joomla! 1.7]]
 +
[[Category:Joomla! 2.5]]

Revision as of 13:02, 7 April 2014

This page has been archived. This page contains information for an unsupported Joomla! version or is no longer relevant. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.


This tutorial is part of the Developing a Model-View-Controller (MVC) Component for Joomla!2.5 tutorial.

The first basic component[edit]

Let's create a Hello World! component.

Public display[edit]

With your favorite file manager and editor, create a file yoursite/components/com_helloworld/helloworld.php containing

Hello world

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!2.5 installation path) after installing this component.

Administrator management[edit]

With your favorite file manager and editor, create a file yoursite/administrator/components/com_helloworld/helloworld.php containing

Hello world administration

You can test this basic component by putting administrator/index.php?option=com_helloworld in your browser address after installing the component.

Packaging an installation zip file[edit]

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.

With your favorite file manager, create a directory (outside your Joomla installation directory) containing

admin/sql/updates/mysql/0.0.1.sql is an empty file allowing to initialise schema version of the com_helloworld component.

admin/sql/updates/mysql/0.0.1.sql

Create a compressed file of this directory or directly download the archive and install it using the extension manager of Joomla. 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 installation under the Components menu.

Note: <name>Hello World!</name> is tricking you into thinking that this is actually only a name, and you could call it 'fluffy' or 'bippo', but this is not true. As far as I understand the name in between the tags is getting automagically lowercased, white spaces and special characters are removed (the ! for example) and joomla starts to look for files/folders responding to this name. So the name you are giving there is actually very crucial for your component to work. In other words, if you would change "Hello World!" to "helloworld" everyhting would still work. If you would change it to "helloworld2" the component would be looking for different folders and file names.

helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="2.5.0" method="upgrade">

	<name>Hello World!</name>
	<!-- The following elements are optional and free of formatting constraints -->
	<creationDate>November 2009</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 in 2.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>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>

Navigate[edit]

Next: Adding a view to the site part

Contributors[edit]