Introduction

What does it do?

MVC is a TYPO3 extension which provides a basic framework on top of TYPO3 4.x that enables building enterprise web applications. It includes:

1.      A MVC Framework for TYPO3 4.x, based on the general FLOW3 concept (different naming). Additional the following stuff:

1.     presentation model concept

2.     TYPO3 specific view helpers

3.     TYPO3 specific simple configuration object (that supports initialisation from typoscript and flexforms)

4.     tx_mvc_extMgm for adding the required typoscript to use MVC Plugins

5.     several frontControllers for adding and executing MVC plugins in TYPO3

6.     simple and flexible form rendering concept

2.       base classes for model objects and repositories. (inspired by DDD - still under refactoring)

3.      filter and validators for adding security to your application

4.      abstraction from common TYPO3 functionalities.

5.      more tools and system classes that offers framework like functionality for building enterprise web applications.

About this extension

The extension is developed and maintained by AOE media GmbH.

It is developed because of the requirement to build clean and scalable web applications in TYPO3 4.x and the need to smaller the gap between other web frameworks especially FLOW3.

 

Motivation

Screenshot of the controller with the default “showlistAction”, the “ajaxshowlistAction” and the “showdetailAction” that belongs to the output above. In this case a composite view is composed together with the sub views: search form, pagination, list. Each with its own model: a model for the search form and a collection of records that are rendered in the list. That's all!

Advantages of MVC / MVP

l  increase testability (unit tests at least for domain layer, also unittests for controllers and views are possible)

l  focus on a clean and maintainable (domain) model without thinking much of the concrete view requirements.

l  Better support fo team development

l  change- and exchangeable views

l  reuse of models

l  defines the base structure of typical applications and offers the base for using other helpful patterns in your application.

 

Quickstart: building new MVC based extensions

 

1) Start normal with the kickstarter and create your tables etc. there. But do not create frontend plugins. Once the basis extension is kickstarted several steps are required to have a working MVC plugin:

 

2) Add a folder “controller” and add a class with the following naming convention “class.<tx-extensionkey>_controller_<controllername>.php” that extends the action controller .

Each controller has <actionname>Action() methods that are automatically called if a argument "action" is found

Each controller has to set some member variables like: argumentNamespace; extensionKey; defaultActionMethodName.

Each action has his view autoloaded and should use $this->view (its a default empty view or the view detected by a naming convention)

This is an example code:

/**
 * Default Controller for the 'objects' extension.
 *
*/
class tx_objects_controller_default extends tx_mvc_controller_action {

      /**
      * @var        string 
      */
     protected $extensionKey = 'objects';

 

     /** 
      * @var        string 
      */
     protected $defaultActionMethodName = 'showlistAction';

 

     /** 
      * @var        string 
      */

     protected $argumentsNamespace = 'objects';

 

      public function showlistAction() {
           return $this-view->render();
     }



3) If you want a plugin (you normally want this). The controller needs to be registered as a plugin, therefore place the following code to ext_localconf.php

$pluginListTypeKey=$_EXTKEY.'_plugin';

tx_mvc_extMgm::addSimplePluginController($_EXTKEY,$pluginListTypeKey,'default');

 

That will add the configuration for a new plugin to TYPO3.

Also you are required to add this to ext_tables.php:

$pluginListTypeKey=$_EXTKEY.'_plugin';
t3lib_extMgm::addPlugin(array('LLL:EXT:objects/locallang_db.xml:tt_content.list_type_pi1',$pluginListTypeKey),'list_type');

 

t3lib_extMgm::addStaticFile($_EXTKEY,"configuration/static/","Objects Outputs");

 

4) If you want to use the autoloading of view, then create a view for your action in the folder “view” following this namingconvention: <controllername>/class.<tx-extensionkey>_view_<controllername>_<actionname>.php

This enables you to access the initialised view object in the action with $this->view.

A minimalistic view could look like:

class tx_objects_view_default_showDetail extends tx_mvc_view_abstractView {
     public function render() {
           return 'Hello World';
     }
}

 

5) Then you should already be able to use a plugin with the “hello world” output.

6) Now add something useful :-). This can start with implementing your model design in the folder “domain”, if useful with the use of the abstract Classes the extension provides. After the functionality of your domain layer is checked with Unittests you are ready to use them in your controller and pass them to the view.

 

The example extension “mvcnews”

There is the extension “mvcnews” that uses most of the features – have a look at that.

It also shows the unobtrusive AJAX implementation –  jquery is required in the FE to see it working – but any other JavaScript framework is also OK.

Its currently in forge.

 

Folderstructure of a MVC based extensions

l  configuration (Place to add the static typoscript code. Place to add the flexform configuration for your plugins)

l  controller (folder that has the controllers. Namingconvention: class.<extensionprefix>_controller_<controllername>.php)

l  domain (the place where to add your domainlogik and domainobjects (DDD)). Suggested subfolders:

      model

l  <optional extension sepcific packages>

      service

l  presentation (presentationmodels (if any))

l  res/templates (default templates for the templateviews)

l  view

  folder that includes the views in subfolders:

  subfolders = controllername

  namingconvention: <extensionprefix>_view_<controllername>_<actionname>.php

l  system (System layer of your extension with useful classes that don't belong to the Domain layer)

Last Tweets (follow)

blogroll
MVC Framework
16.05.09 - Find parts of the offical manual + some extra Infos for the MVC extension.
Ajax Framework (fe_ajax)
06.08.08 - Easy way to get barrierfree AJAX features in your extension