The Model-View-Controller (MVC) paradigm is a valuable, user input directed, solution approach for software program development. The background for the MVC approach to software development is the need for clearer, largely re-useable, program code. In TYPO3 programming, the MVC paradigm is mostly used when developing extensions.
The MVC paradigm, with regard to TYPO3, includes:
- Model: the Model administers the data in combination with the application logic.
- View: the View is responsible for presenting the data, once the model has created it. It calls up and presents information from the model. It is updated on all changes to the model and accepts user input.
- Controller: the Controller enables user control, receives user actions, evaluates them and responds accordingly. It attributes the actions to specific operations within the model.
Usually a View and a Controller work together, while the pure model, initially, is unaffected by either. In some complex application cases, several models are programmed and directed from a single View and Controller. The MVC concept enables program code that is not only reusable, but also easily alterable at a later date.
- The advantages of the MVC approach
- Sections of programming are as much as possible independent of one another
- Clearer program code as regards the complexity and the wrapping of component parts
- MVC encourages programmers to write well-structured code
- Programmers can fully use their capabilities at their individual skill level
- All components are exchangeable and reusable
And, very importantly:
The next generation TYPO3 Phoenix, which is not yet available, will fully support the MVC approach to object-oriented programming. Thus it makes solid sense for TYPO3 programmers to already switch over to MVC for their development work.
- Developing extensions with MVC
Anyone wanting to try their hand at developing their own MVC-based extensions currently has four options open:
- Either use the two MVC extensions "lib/div", which give access to class directories for MVC programming in TER;
- Or use the MVC paradigm to program by hand, in other words: program Model, View and then the Controller in PHP; after this, integrate the program sections into a framework you have generated in Kickstarter, before completing the extension.
- Starting with TYPO3 4.3 the new "extbase"- extension is included. With extbase it is possible to develop and program extensions based on the MVP paradigm. And furthermore these extensions are downwards compatible with FLOW3.
- AOE media has also developed its own TYPO3-based MVC-Framework. It integrates concepts from MVC and Domain-driven Design in a TYPO3 Core and is used to support our realization of high performance TYPO3 applications and Extensions.
- Developing using "lib/div" extensions
The first variant here is certainly the most simple:
- Download the extensions "lib", "div" and "kickstarter mvc" from the TER in TYPO3 and install them;
- Create a new extension in Kickstarter;
- In the new extension folder, you will find automatically generated sub-folders called "controllers", "models", "static", "views" and "views/template";
- Via "lib/div" you can now find 9 different PHP classes for the titling of data-objects or object-arrays depending on either the model approach, the PHP-View data or the PHP-Controller file.
- Using standard PHP coding, class data can now be embedded in the meaningful program logic of an extension.
- Development with a self-programmed MVC extension
In principle it is also possible to develop one's own MVC extension and then integrate it into the TYPO3 framework. This has the advantage that alongside the division of the Source Codes into the three parts: Model, View and Controller, other adaptations are possible to meet real requirements. For example, class directories you require over and over again can be integrated into your own MVC-Extension for Frontend extension development. In this way both the development time and programming costs can be significantly reduced.