Writing controllers and views

Moufla: a new generation MVC framework for Joomla

Moufla_logo

Why should I care?

Moufla is a MVC framework for Joomla. Actually, it is a bridge between Joomla and the Splash MVC framework used by Mouf-PHP (a dependency injection based framework).

Moufla offers the following features:

  • compatible controllers, declared through a nice graphical DI container
  • PSR-7 compatibility: your controllers can take into parameter Request objects and respond Response objects that are compatible with the PSR-7 HTTP Message interfaces.
  • use of annotations in your controllers (for instance: @URL to declare a new route, @Logged to restrict access to logged users, etc...)
  • support for any kind of views supported in Splash MVC (this includes plain PHP files, Twig templates, etc...)
  • a nice web-based UI to scafold your controllers and views
  • integration of your views inside the Joomla theme
  • (very) easy Ajax support

Another interesting feature is that your code is 100% compatible with Splash MVC. This means that:

  • You can write a controller in Splash MVC and deploy it later in Joomla (or the opposite)
  • Since there is also a Drupal module for Splash (Druplash), and a Wordpress module for Splash (Moufpress), you can actually write a controller in Joomla and deploy it in Drupal or Wordpress (or the other way around). Yes, you read it correctly, you can develop an application that will run on Wordpress, Drupal and Joomla (!) Haha! I see you're interested. Let's get started!

Supported Joomla version

Moufla 2.x is compatible with Joomla 3.x and Splash MVC 7.x.

Installation

You will first need to install Joomla and Mouf side by side.

  1. Start by installing Joomla as you would normally do.
  2. Install the Mouf PHP framework in the same directory as Joomla This means you should have the composer.json file of Composer in the same directory as the configuration.php of Joomla.
  3. Modify composer.json and add the moufla module. Your composer.json should contain at least these lines:

    {
        "autoload" : {
            "psr-4" : {
                "MyApp\\" : "src/MyApp"
            }
        },
        "require" : {
            "mouf/mouf" : "~2.0",
            "mouf/integration.joomla.moufla" : "~2.0"
        },
        "minimum-stability" : "dev",
        "prefer-stable": true
    }
    

    Do not forget to customize your vendor name (the MyApp part of the autoloader section).

  4. Create the empty src/ directory at the root of your project.
  5. Run the install process in Mouf: connect to Mouf UI (go to localhost/your_folder/vendor/mouf/mouf) and run the install process for all the packages (including the Moufla install process of course)

Getting started

In the next section, we will learn how to create a controller and a view.

Or if you already know Splash, you can directly jump to another part of this documentation:

Writing controllers and views

Found a typo? Something is wrong in this documentation? Just fork and edit it!