READMEConfiguring a BCE Form

Quick Start Guide

In this quick start guide, we will see how you can use BCE to build a user form

Our playground data model

The first thing you have to know, is that BCE directy relies on your application's ORM system. For now, Mouf's ORM system is TDBM, but when others will be available, we will do our best to provide multi-ORM support. You will find a detailed description of BCE's architecture in the dedicated chapter Detailed Architecture

Data Model

Requirement : BCE needs a specific TDBM setting. You must turn the defaultAutoSaveMode to false in the "tdbmService" instance*

Create and configure the form instance

First thing you have to do is creating a BCEForm instance. The BCEForm class represents a form. This is done, as usual, by hiting the "create a new instance" item of the ribbon menu. For example, we create a userForm instance :

Create User Form

Once you've done this, you reach usual instance interface of Mouf. As explained the the readme, a dedicated interface assists you in creating and configuring your form : press the "configure form" button just under the title of the instance page. You will reach the configuration screen. Now, as explained above, BCE relies on the ORM system. You will first have to choose the DAO that handles the main entity the form should manage, in our case, we will choose the UserDAO :

Choose Dao

Once you choosed your DAO, the default form configuration will load automatically : each column of the user table will be mapped with a field descriptor (please read the Detailed Architecture for more information on field descriptors).

In this exemple, we will leave everything to default.

Configure Form

Simply configure the form's action to submit to the saveUser URL. To do so, click Configuration >> Form Attributes, then modify the "Form Action URL" field

Set save URL

Note : If the data model changes, and you add a column, it will be automatically detected and suggested. If you remove a column, you will have to remove the field descriptor manually

Write a simple controller & view

We will assume, you already now about splash and its MVC implementation. If not, please refer to Splash documentation to understand what comes next.

Create a controller class (let's say the UserController), that has 2 actions: editUser and saveUser. Add a userFormInstance property of the BCEFormInstance class.

     * @var BCEFormInstance
    public $formInstance;

     * User edition page.
     * @param string $id the user's id (null for creation)
     * @URL editUser
    public function editUser($id = null) {

        $this->content->addFile(ROOT_PATH."src/views/user/edit-user.php", $this);

     * Save the user into DB.
     * @URL saveUser
    public function saveUser() {
        $id = $this->formInstance->save();

        if ($id){
            set_user_message("User has been saved", UserMessageInterface::SUCCESS);
            set_user_message("An error occured while saving the user", UserMessageInterface::ERROR);


create the view for displaying the form :

use Test\Controllers\UserController;
/* @var $this UserController */
<h1>Edit User</h1>

Then, bind those instances together : the userController with the formInstance, and the userForm to the formInstance

Bind userForm to form instance


Refresh the cache for registering the new URLs, and goto the /editUser page (or editUser?id=1 for user edition)

Renderer edit form


Using very few lines of code, and less than 5 minutes in mouf's configuration interface we manaaged creating a simple form, that contains every field of the user table (note that the role field is a dropdown list of items of the role table, and the birth date field is already a datepiker without any further configuration).

But this was just the begining : the generated form is missing some fields (only the ones directly related to the user table are displayed)...

Next Steps : * In order to get a better understanding of the BCE library, you should read the "Detailed Architecture" chapter. * Or you might rather like to continue the overview of BCE capabilities, next chapter is "Configuring BCE Forms" chapter.

READMEConfiguring a BCE Form

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