J3.x

Developing an MVC Component/Developing a Basic Component: Difference between revisions

From Joomla! Documentation

MATsxm (talk | contribs)
m Marked for translation
MATsxm (talk | contribs)
Marked this version for translation
Line 2: Line 2:
{{:J3.1:Developing a MVC Component/<translate><!--T:1-->
{{:J3.1:Developing a MVC Component/<translate><!--T:1-->
en</translate>}}
en</translate>}}
<translate>== The first basic component ==
<translate>== The first basic component == <!--T:3-->
Let's create a ''Hello World!'' component.</translate>
Let's create a ''Hello World!'' component.</translate>
<translate>=== Public display ===
<translate>=== Public display === <!--T:4-->
With your favorite file manager and editor, create a file <tt>''yoursite/components/com_helloworld/helloworld.php''</tt> containing:</translate>  
With your favorite file manager and editor, create a file <tt>''yoursite/components/com_helloworld/helloworld.php''</tt> containing:</translate>  


Line 11: Line 11:
</source>
</source>


<translate>Also Create an empty file <tt>''yoursite/components/com_helloworld/helloworld.xml''</tt></translate>
<translate><!--T:5-->
Also Create an empty file <tt>''yoursite/components/com_helloworld/helloworld.xml''</tt></translate>


<translate>The last step is install the component, go to Extensions {{rarr}} Extension Manager {{rarr}} Discover :: Discover (Button).
<translate><!--T:6-->
The last step is install the component, go to Extensions {{rarr}} Extension Manager {{rarr}} Discover :: Discover (Button).
Select the component and install it with the installation (button).</translate>
Select the component and install it with the installation (button).</translate>


<translate>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! 3.x installation path) after installing this component.</translate>
<translate><!--T:7-->
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! 3.x installation path) after installing this component.</translate>


<translate>=== Administrator management ===</translate>
<translate>=== Administrator management === <!--T:8--></translate>
<translate>With your favorite file manager and editor, create a file <tt>''yoursite/administrator/components/com_helloworld/helloworld.php''</tt> containing:</translate>  
<translate><!--T:9-->
With your favorite file manager and editor, create a file <tt>''yoursite/administrator/components/com_helloworld/helloworld.php''</tt> containing:</translate>  


<source lang="php">
<source lang="php">
Line 25: Line 29:
</source>
</source>


<translate>You can test this basic component by putting  
<translate><!--T:10-->
You can test this basic component by putting  
<tt>'''administrator/index.php?option=com_helloworld'''</tt> in your browser address after installing the component.</translate>
<tt>'''administrator/index.php?option=com_helloworld'''</tt> in your browser address after installing the component.</translate>


<translate>=== Pack an installation zip file ===</translate>
<translate>=== Pack an installation zip file === <!--T:11--></translate>
<translate>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.</translate>
<translate><!--T:12-->
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.</translate>


<translate>With your favorite file manager, create a directory (outside your Joomla! installation directory) containing:</translate>
<translate><!--T:13-->
With your favorite file manager, create a directory (outside your Joomla! installation directory) containing:</translate>
* ''[[#helloworld.xml|helloworld.xml]]''
* ''[[#helloworld.xml|helloworld.xml]]''
* ''[[#site/helloworld.php|site/helloworld.php]]''
* ''[[#site/helloworld.php|site/helloworld.php]]''
Line 42: Line 49:
* ''[[#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''
* ''[[#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''


<translate>Create a compressed file of this directory or directly download the [https://github.com/scionescire/Joomla-3.2-Hello-World-Component/archive/step-1-basic-component.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.</translate>
<translate><!--T:14-->
Create a compressed file of this directory or directly download the [https://github.com/scionescire/Joomla-3.2-Hello-World-Component/archive/step-1-basic-component.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.</translate>


<translate>==File Details==</translate>
<translate>==File Details== <!--T:15--></translate>
{{vanchor|admin/sql/updates/mysql/0.0.1.sql}}
{{vanchor|admin/sql/updates/mysql/0.0.1.sql}}
<translate>is an empty file allowing to initialise schema version of the com_helloworld component.</translate>
<translate><!--T:16-->
is an empty file allowing to initialise schema version of the com_helloworld component.</translate>


<source lang="sql">
<source lang="sql">
Line 118: Line 127:
{{vanchor|index.html}}
{{vanchor|index.html}}


<translate>common to all folders</translate>
<translate><!--T:17-->
common to all folders</translate>


<source lang="html4strict">
<source lang="html4strict">
Line 124: Line 134:
</source>
</source>
<br />
<br />
{{notice|<translate>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.</translate>}}
{{notice|<translate><!--T:18-->
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.</translate>}}


<div class="row">  
<div class="row">  
<div class="large-6 columns">{{Basic button|<translate>S:MyLanguage/J3.x:Developing_a_MVC_Component/Introduction|Prev: Introduction</translate>|class=expand success}}</div>
<div class="large-6 columns">{{Basic button|<translate><!--T:19-->
<div class="large-6 columns">{{Basic button|<translate>S:MyLanguage/J3.x:Developing_a_MVC_Component/Adding_a_view_to_the_site_part|Next: Adding a view to the site part</translate>|class=expand}}</div>
S:MyLanguage/J3.x:Developing_a_MVC_Component/Introduction|Prev: Introduction</translate>|class=expand success}}</div>
<div class="large-6 columns">{{Basic button|<translate><!--T:20-->
S:MyLanguage/J3.x:Developing_a_MVC_Component/Adding_a_view_to_the_site_part|Next: Adding a view to the site part</translate>|class=expand}}</div>
</div>
</div>



Revision as of 15:28, 1 July 2015

Joomla! 
3.x
Tutorial
Developing a MVC Component



This is a multiple-article series of tutorials on how to develop a Model-View-Controller Component for Joomla! VersionJoomla 3.x.

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.

Public display

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

Hello world

Also Create an empty file yoursite/components/com_helloworld/helloworld.xml

The last step is install the component, go to Extensions    Extension Manager    Discover :: Discover (Button). Select the component and install it with the installation (button).

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

Administrator management

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.

Pack 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.

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

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.

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>


General Information

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.