File Structure and Naming Conventions/fr

From Joomla! Documentation

This page is a translated version of the page J4.x:File Structure and Naming Conventions and the translation is 6% complete.

Other languages:
Deutsch • ‎English • ‎français
Info non-talk.png
General Information

Vous trouverez dans ce document les nouvelles conventions spécifiques à Joomla 4. Joomla 4 reprends également les anciennes conventions de nommage de Joomla 3 à des fins de rétro-compatibilité. Si vous voulez avoir le support de Joomla 3 et de Joomla 4 en même temps vous devriez continuer à utiliser les conventions de Joomla 3 que vous trouverez dans le document Structure des Fichiers et Conventions de Nommage pour Joomla 3

Les Composants dans le Noyau de Joomla (et généralement dans l'éco-système Joomla) suivent le modèle de conception Model-View-Controller (MVC). Ce modèle sépare l'activité de collecte des données (Model), de présentation (View) et d'interaction des utilisateurs (Controller) d'un composant. Cette séparation

Joomla's file loading system enables developers to work with separate files for controllers, views and models without worrying about importing the right file in the right place. However, for this to work, certain naming conventions need to be observed.

The Joomla platform is extremely flexible, and it is possible to diverge from these conventions in many ways. It is nonetheless recommended to apply standard naming wherever possible to increase readability and maintainability. Additionally, the platform will take care of the many tedious class management tasks when the files and classes of a component are named correctly.

Reserved words

There are reserved words which can't be used in names of classes and components.

An example is the word "model" (in any case) for model classes (except "model" that must be second part of that class name)[1]. Because the first part of the name of model classes is the same as the controller class name, controller class names can't contain the word "model" either. And because of the conventions (although violating it won't produce an error), controller class names must contain the component name, so component names can't contain the word "Model" either. So components can't be named "com_modelling", or if they are, they must violate the naming conventions and have a different base controller class name (or have some other hacks).

Installation package vs. actual file placement

All Joomla extensions must be packaged as a .zip installation file. According to the most common file arrangement, the package should contain at least the admin folder in its basic structure. It may additionally contain (amongst others):

  • site
  • admin

If you set up your XML manifest file according to standard practice, the contents of site will be installed to /components/com_{componentname}, whereas the contents of admin will be installed to /administrator/components/com_{componentname} (N.B. In these paths the component name is lowercase).

The /site folder

This folder keeps the files for the frontend part of the component.

This folder holds the XML forms used by \Joomla\CMS\Form\Form.
This folder holds the views to be rendered in the template.
This folder holds the files for the view {ViewName} (note the path here uses the view name in lowercase).
This is the default template for the view {ViewName}. In this PHP file, the $this keyword refers to the view class that the template belongs to.
This folder holds the namespaced PHP code for the frontend of the component. For the conventions of what the namespaces will be please refer to Namespace Conventions in Joomla 4
This folder holds the different views for the component.
This file is the entry point for the view {ViewName}. This class must implement the interface \Joomla\CMS\MVC\View\ViewInterface and will extend from the format specific class (if core provides it - such as \Joomla\CMS\MVC\View\HtmlView) or from \Joomla\CMS\MVC\View\AbstractView. The filename is related to the format the view will be loaded in. For example, if the format URL parameter is set to format=feed, the file FeedView will be loaded.
This folder holds additional models, if needed by the application.
This file holds the model class {ModelName}. This class must extend the base class \Joomla\CMS\MVC\Model\BaseDatabaseModel. Note that the view named {ViewName} will by default load a model called {ViewName} if it exists. Most models are named after the view they are intended to be used with, but this is not a requirement. See Using multiple models in an MVC component for more information.
This folder holds additional controllers, if needed by the application.
This file holds the controller class {ControllerName}. This class must extend the base class \Joomla\CMS\MVC\Controller\BaseController.
This folder holds the site dispatcher.
This file holds the site dispatcher. It loads the language files, does a component access check and then gets and executes the controller, in components with HTML output also executing redirects if required.

The /admin folder

The file structure is almost exactly the same as in the /site folder. Note that the view, models, controllers etc. of the site and admin parts are by default completely separated, and have nothing to do with each other - the site part and the admin part can be thought of as two different components! A view in the /admin folder may have a counterpart with the same name in the /site folder, yet the two views have nothing in common but their class names (although they will have different namespaces to separate them).

There are two additional parts in the administrator directory:

This folder holds a single file.
This file holds an anonymous class implementing \Joomla\DI\ServiceProviderInterface. It's job is to return the Dependency Injection container provisioned with all the factories needed to run your component (in all 3 web applications they may run in).
This folder holds a single file.
This file is the public face of the extension, it retrieves data from the Container produced in the provider file above and exposes the relevant services (accessible via \Joomla\CMS\Application\CMSApplication::bootComponent()). This class is used by modules to get access to the component models or to run a component by Joomla when loading a page (by getting the dispatcher).

In some cases it might sometimes make sense to share classes between the site and admin parts of the component. Especially models can be shared to avoid duplicating model code. The Joomla platform supports this strategy. When sharing any code between site and admin applications, the classes should be designed with great care to avoid the possibility of a site user executing admin actions.

  1. Reason is in the getName function in file libraries/src/MVC/Model/BaseDatabaseModel.php: if (!preg_match('/Model(.*)/i', get_class($this), $r))