UML2.1 to Php generator

UML2.1 to Php generator.

The goal of this generator is to produce a PHP5 application using PEAR Framework and SMARTY templates engine.


PHP5 application generation

This demonstration shows how to generate a PHP5 application with an UML2 model.

Use of the generated code

This demonstration illustrates how to use the generated code, implementing the following features :

  • Author creation
  • Displaying authors
  • Selection and removal of several authors

Modification of the model and regeneration of the code.

Here is the demonstration of the incremental generation. This functionality is illustrated by adding a 'nickName' attribute to the 'Author' class  .

Target architecture

This module generates a PHP5 application structured with layers :

  • DAO
  • Business Objects
  • Presentation

DAO layer with PEAR DB Framework

DAO layer is made up of classes allowing the application to execute queries to a data base. All DBMS supported by PEAR DB Framework are compliant with the generated application. A DAO class is created for each business object.

The generator deals with :

  • Inheritances (one table per class)
  • Enumerations
  • Associations (1-1, 1-*, *-*)
  • Queries (technical id or all business objects of a specific type).
  • Insertion which cascade updates
  • Cascade updates
  • Deletion

Business Objects

Business Objects are POJO having attributes and corresponding getters/setters. With an aim of facilitated the application development, classes managing lazy loading are generated using the Proxy Design Pattern.

Presentation layer

The Presentation layer of the generated application presents the following characteristics :

  • A SMARTY template is generated for each class having a Screen stereotype
  • A SMARTY template allowing to display and to select some business objects is generated for each class having a Entity stereotype
  • A controller class is generated for each class having a Screen stereotype. Those classes know the model and choose views. The controllers execute actions.
  • An index file is generated. It is used as the main controller. It is the entry point of all the requests made by users.

Operation and use of the module.

Modelisation UML

The generator produce code from UML2.1 models enhanced with a few stereotypes.

You may use different modelers with this generator : Topcased, Papyrus or the UML2 Tools Eclipse project.

The input model

The generator uses classes of the input model to generate the PHP 5 application.

We identify two kinds of class :

  • Classes having a stereotype named Entity allow the generation of the business part of the application (DAP, business objects)  ;
  • Classes having a stereotype named Screen allow the generation of the presentation part of the application (SMARTY templates, controllers).

Files generated from one classe having a stereotype named Entity.

  • Part of the database creation script
  • DAO class (into dao folder)
  • Entity class (into entity folder)
  • Entity class managing lazy loading (into entity/proxy folder)
  • EntityFactory class allowing to create entity instances
  • SMARTY template allowing to display this business object

Files generated from one classe having a stereotype named Screen.

  • Part of the index file.
  • Controller class (into navigation/controler folder)
  • SMARTY template (into navigation/view folder)

Others generated files

  • File importing all required dependencies (common/common.php5)
  • Configuration class (common/config.php5)
  • File including statements to create database sequences (common/dbseq.php5)
  • IEntity interface (entity/IEntity.php5)
  • Entity abstract class (entity/Entity.php5)


Module status


Business Objects


Presentation - Controller


Presentation - SMARTY & CSS


Others (Logging, ...)





The installation process is explained on the Installing a generative module page . The generated application needs PEAR Framewark and SMARTY templates engine.

Quick start

As soon as the generator is installed, you may quickly test it's working nicely. Create a new project (an empty project or PHP project if you installed the PDT plugin).

Choose the File menu entry then New and Other....

In the Acceleo category pick Module Launcher.

The installed modules is then available. Choose the "UML2 to Php" module then click on "next". Fill in the parameter fields

Once the wizard is finished it will create a .chain file allowing you to launch the generation and it will initialize a default Ecore model.

Right-clicking on the .chain file the Launch button will kick off the generation process. You'll find the generated PHP files in the folder you choosed with the wizard.

Contribute !

If you want to change or complete the generative templates you may use the a Team Project Set file. Using this file you'll be able to import the module sources right from the Subversion repository inside your Eclipse.

Team Project Set file for PHP module

The getting and modifying generator module sources page explains how to use this file.