Extbase and Fluid follow the principle of Convention over Configuration. That means that many tasks will work out of the box if you respect certain naming conventions for classes, files, and method names. Furthermore, this principle improves the consistency and readability of your code. Thus it is much easier for extension developers to understand how unknown extensions (based on Extbase) work because the structure is always the same, and common tasks are solved in the same way.
With Extbase and Fluid, we set quite an emphasis on the intuitive and logical naming scheme of classes, methods, and variables. Our goal is to provide the source code as readable as possible because the names are already reflecting what the source code does.
Generally, classes are written in
UpperCamelCase, and methods and variables are
lowerCamelCase. Besides, the name must be detailed and meaningful.
Abbreviations are to be avoided.
Every extension based on Extbase contains certain folders in the main directory:
- Here resides the complete source code for the extension. Only PHP files are allowed, each one containing exactly one class or interface. All classes (or interfaces) are loaded via the autoloader mechanism when needed.
- The configuration of the extension is located here: FlexForm configuration, TCA definitions, TSconfig, and TypoScript files. Subfolders can be created when they are needed or helpful.
- Contains the documentation of the extension.
This folder contains static resources of the extension. This means all files which are not PHP files but are necessary for the execution of the extension. This might be code from libraries, template files, images, CSS files, and so on.
It is distinguished between public (
Public/) and private (
Private/) resources. In the folder
Private/there should be a
.htaccessfile, blocking direct access to non-public files.
- Contains non-public resources of the extension.
Contains public resources of the extension.
Within these two folders, the authors of the extension can choose the structure freely, but we recommend the following structure:
- This is a good place for images, CSS files, or media files delivered directly to the client.
- Here are the default Fluid templates for the extension.
Contains PHP code, which is not compatible with the naming conventions like external PHP libraries, procedural code, and so on. If you run TYPO3 in composer mode, you should define the autoloading for said folder in the
composer.jsonof your extension.
If you do not run TYPO3 in composer mode, the autoloader of TYPO3 will automatically search for php files in all extensions.
- All unit tests are found here. The structure should be the same as in
Classes. All test classes should end with
- Contains the configuration for the extension manager of TYPO3 like metadata as the name, the description, and the author of the extension.
- This file contains the configuration of the Frontend Plugins.
- This file contains configuration for the backend.
- This is a file with SQL commands for the definition of the database tables.
File and class names¶
Class names in Extbase are composed of the following parts:
- the vendor prefix. For example, if your name is
Example, this part could be
- the name of the extension in
UpperCamelCase. For example, if the extension-key is
blog_example, then this part of the class name is
- the path within the
Classes/folder down to the folder, where the file containing the class resides.
In table A-1, you see some naming examples for file and class names.
Table A-1: Examples for class names
|class name||extension key||folder|
Interfaces end with
Interface, for example
With abstract classes the last part of the name always begins with