Get into FLOW3 with Extbase

Categories: Community Created by Michiel Roos
A key feature of TYPO3 is its extendability and flexibility. Writing extensions was never easier since the Kickstarter and tslib_piBase. But time doesn't stand still; new programming paradigms and other frameworks come up. Time to take a next step to faster, cleaner extension coding. During this talk we got in touch with the features of the new framework for extension development that will be introduced in TYPO3 4.3. We also dug into the internals of the framework to understand how it supports your development process.

Currently there are more than 3750 extensions in the extension repository. Most of these extensions are written in the old fashioned way; by extending the tslib_piBase class. Most developers use the Kickstarter to build their first few TYPO3 extensions. The Kickstarter usually (depending on the type of extension) creates an extension with a single plugin directory that contains a single class file. All code lives in this class file. As your extension grows larger this file can get quite large. It is good practice to split the work that is being done inside this file into functions that do a specific task like fetching records from the database or fetching the template and filling the markers with information from the records. The single file can also be split into multiple files so you can put all the database related functions in one file and all template rendering functions in another file.

Using the Model View Controller paradigm in TYPO3 extension building has become more popular lately. Several extensions and extension libraries use MVC to split their code cleanly into Models, Views and Controllers. Life is better now.  

FLOW3 (the PHP framework on which TYPO3 5.0 will be built) brings us a lot of good things. A lot of new coding techniques are used that make life of the extension developer a lot easier. For example, you no longer have to deal with direct database access, you work with objects only. The framework handles the fetching and storing the data. You can validate data just by adding a single line of code to the function description. You can use several standard validation methods, or you can define your own.

Jochen Rau started to code for TYPO3 two and a half years ago. He started using the Kickstarter and later used a MVC library to build his extensions with. When Jochen and FLOW3 met, it was love at first sight. Jochen wanted to use the FLOW3 goodness in the current TYPO3, so he backported some parts of the FLOW3 code (the Component-Manager, Dependency Injection and the Auto-Wiring features) into an extension called 'gimmefive'. Currently there is one big project that uses the 'gimmefive' extension: 'mailformplusplus' which is as you guessed, a MVC implementation of mailformplus. But the FLOW3 code evolves quickly and the 'gimmefive' extension needed frequent updates.

His second attempt made in late October 2008 is called 'thebridge'. It runs FLOW3 in parallel to TYPO3 4.x. After a plugin is detected the whole rendering process of the Extension is handed over to FLOW3. Needless to say . . . it's quite slow to run two frameworks in parallel. Even rendering a list of news takes some time using this approach.

His third attempt is Extbase and does not share a single line of code with 'gimmefive'. The core team thought it was a good idea to make Extbase a part of the TYPO3 core in the upcoming 4.3 release. In 4.3 you will be able to create extensions using this new MVC extension base library. Apart from very clean and lightweight code there is an added bonus when you create code using the new Extbase; Your code will run on future TYPO3 5.0 with minor modifications! That's right. All extensions created for TYPO3 4.3 using Extbase will run on TYPO3 5.0 with only minor changes.

The community would hereby like to give a 'big thumbs up' to the 5.0 team who have worked very hard to make this wonderful code available to the world. All of the paradigms and 90% of the code of Extbase are directly taken from FLOW3. Finally, 'reusable code'!

Sebastian Kurfurst, a member of the 5.0 core team is also the creator of the new templating system called package-fluid that will be used for FLOW3. The new templating moves the code for the view logic to the template. For example, it is now possible to use looping constructs in the template. This means that you no longer have to handle the weird substitueMarker and other templating functions which were particularly nasty when using template parts and sub parts.

<f3:for each="{blogPosts}" as="post">
  Title: {post.title} <br />

If you conform to certain coding conventions, the system can take almost all the work out of your hands. The only thing you need to concern yourself with is the Model. Most of the Control and View code is already present in Extbase, you just use it transparently. All you need to do is come up with a clear Model that maps closely to the problem domain and write some code and some templates.

If this sounds like something too good to be true . . . know that a Irene Huppner (yes, a TYPO3 chick ;-) wrote the initial version of the package-forge extension using the FLOW3 extension framework in a couple of hours. Well, not a complete forge implementation, but the basic frontpage view, project creation, deletion and editing and a list of projects. The idea is to extend on this extension so that it may one day replace the current forge code (redmine, running on the rails framework) with our FLOW3 implementation. Irene wrote only about 15 lines of actual code to accomplish this feat. The rest of the logic needed is in the templates on which she spent the most time. And again, as an added bonus, all code written can be used in TYPO3 5.0!

Extbase can be seen as a bridge between TYPO3 4.3 and 5.0. So please all head over to and get yourself the latest 4.3 code, the FLUID and the Extbase extension and convert your favorite TYPO3 extension to Extbase based code. Work has started on a new kickstarter with which you can kickstart an Extbase extension. When 4.3 comes out, the kickstarter may be mature enough to use and there may even be some more documentation to support you. But hey, you can read code . . . so . . . get to work!


Have Fun!

Michiel Roos [Netcreators]