Base assoluta su Come funziona un Componente

From Joomla! Documentation

This page is a translated version of the page Absolute Basics of How a Component Functions and the translation is 18% complete.

Other languages:
বাংলা • ‎Deutsch • ‎English • ‎español • ‎فارسی • ‎français • ‎हिन्दी • ‎Bahasa Indonesia • ‎italiano • ‎Nederlands • ‎Nederlands (informeel)‎ • ‎português do Brasil • ‎română • ‎русский • ‎українська

Questo articolo è per principianti di Joomlaǃ; è progettato per spiegare cos'è un componente di Joomlaǃ e come funziona. Questo articolo farà riferimento ad un esempio di componente denominato Hello Worldǃ.

Cos'è un Componente di Joomlaǃ

A component is a kind of Joomla! extension. Components are the main functional units of Joomla!; they can be seen as mini-applications. An easy analogy would be that Joomla! is the operating system and the components are desktop applications. Created by a component, content is usually displayed in the center of the main content area of a template (depending on the template).

Most components have two main parts: an administrator part and a site part. The site part is what is used to render pages of your site when they are requested by your site visitors during normal site operation. The administrator part provides an interface to configure and manage different aspects of the component and is accessible through the Joomla! administrator application.

Joomla! comes with a number of core components, like the content management system, contact forms and Web Links.

See also: Module, Plugin, Template

Nel framework di Joomla!, i componenti possono essere progettati utilizzando un modello flat (restituisce il codice HTML per la pagina richiesta) o Model-View-Controller (di seguito definito MVC).

Introduzione all'MVC

MVC è un modello di progettazione di software che può essere utilizzato per organizzare il codice in modo che la logica di business e di presentazione dei dati siano separate. La premessa alla base di questo approccio è che, se la logica di business è raggruppata in una sezione, allora l'interfaccia e l'interazione utente che circonda i dati possono essere modificate e personalizzate senza dover riprogrammare la logica di business. MVC è stato originariamente sviluppato per mappare l'input tradizionale, elaborazione, l'output in una logica di architettura GUI.


Il model è la parte della componente che incapsula i dati dell'applicazione. Spesso forniscono routine per gestire e manipolare i dati in modo significativo in aggiunta alle routine che recuperano i dati dal modello. In generale, la tecnica che sta sotto ai dati di accesso dev'essere incapsulata nel model. In questo modo, se un'applicazione sta per essere spostata da un sistema che utilizza un file di testo per memorizzare le informazioni a un sistema che utilizza un database, il modello è il solo elemento che deve essere cambiato, non la view o il controller.


The view is the part of the component that is used to render the data from the model in a manner that is suitable for interaction. For a web-based application, the view would generally be an HTML page that is returned to the user. The view pulls data from the model (which is passed to it from the controller) and feeds the data into a template which is populated and presented to the user. The view does not cause the data to be modified in any way, it only displays the data received from the model.


The controller is responsible for responding to user actions. In the case of a web application, a user action is generally a page request. The controller will determine what request is being made by the user and respond appropriately by triggering the model to manipulate the data appropriately and passing the model into the view. The controller does not display the data in the model, it only triggers methods in the model which modify the data, and then pass the model into the view which displays the data.

Joomla! Component Framework Explained


In the Joomla framework, models are responsible for managing the data. The first function that has to be written for a model is a get function. It returns data to the caller. For this example, the caller will be the HelloWorldViewHelloWorld view. By default, the model named HelloWorldModelHelloWorld residing in site/models/helloworld.php is the main model associated to this view.

So let's have a quick look at the naming conventions with an example, since the naming convention are the actual magic, that make everything work:

The class HelloWorldViewHelloWorld resides in site/views/helloworld/view.html.php and will make use of the class HelloWorldModelHelloWorld in the file site/models/helloworld.php

So let's just assume we want to use an imaginary view fluffy, you would have to have:

The class HelloWorldViewFluffy which resides in site/views/fluffy/view.html.php. The view will make use of HelloWorldModelFluffy in the file site/models/fluffy.php. Note: the actual screen of the view: site/views/fluffy/tmpl/default.php is required as well to make this example work.

Breaking any of these bold conventions will lead to errors or a blank page.

Accessing a Joomlaǃ Component

First we need to access the Joomla! platform, which is always accessed through a single point of entry. Using your preferred web browser, navigate to the following URL:

1 user access <yoursite>/joomla/index.php
2 administrator access <yoursite>/joomla/administrator/index.php

Hello World! example: localhost/joomla/index.php

You can use the URL of the component, or a Menu in order to navigate to the component. In this article we will discuss using the URL.

1 user access <yoursite>/joomla/index.php?option=com_<component_name>
2 administrator access <yoursite>/joomla/administrator/index.php?option=com_<component_name>

Hello World! example: localhost/joomla/index.php?option=com_helloworld

MVC Basic Directory Structure

Components are stored in a directory within your Joomla! installation, specifically at:

  • htdocs/<path_to_joomla>/components/com_<component_name>/ .

The Hello World! component would be stored in htdocs/<path_to_joomla>/components/com_helloworld/.

A basic component will contain the following files within its directoryː

  • A html file that is just a security file with a background colorː index.html
  • A php file that represents the controller itselfː controller.php
  • A php file that loads the controller classː <component_name>.php
  • A php file that represents the model itselfː models/<component_name>.php
  • Another html file for background controlː models/index.html
  • A php file containing the default viewː views/<component_name>/tmpl/default.php
  • A xml file for adding a menu item typeː views/<component_name>/tmpl/default.xml
  • Another html file for background controlː views/<component_name>/tmpl/index.html
  • Another html file for background controlː views/<component_name>/index.html
  • A php file for displaying the viewː views/<component_name>/view.html.php


The following line is commonly found at the start of Joomla! PHP files:

    defined('_JEXEC') or die('Restricted Access');

This enables for a secure entry point into the Joomla! platform. JEXEC contains a detailed explanation.

Tutorials on Designing a MVC Component

To learn how to design your own MVC Component, please complete the tutorial for your Joomla! version.