ZF2 subforms usage and validation

zf2Differently from Zend Framework 1, I couldn’t find any good documentation about the usage of subforms in Zend Framework 2.
After a bit of investigation, I understood how to use them.
When the subforms extend the `Fieldset` ZF2 class, they can be added to the form with a name, and that name (e.g. subform1 and subform2) will be used with getData() and setData() as a key of the subform data array.
The validation can stay in each related subform, the isValid() ZF2 Form will recursively validate all the subforms.
Example:
A `MainForm` contains two subforms (named `subform1` and `subform2`) of the same class `SubForm`.
Once filled in, getData() will return the following. Equally, the same array structure will fill in the related fields.
    $data = array(
      ‘formElement’ => ‘…’,
      ‘subform1’ => array(
         ‘first’ => ‘…’,
         ‘second’ => ‘…’,
      ),
      ‘subform2’ => array(
         ‘first’ => ‘…’,
         ‘second’ => ‘…’,
      )
    );
Here the code:

Doctrine 2 + zf2 working with both SQL server and MySQL

The web application I’m working on (PHP 5.3, zf2, Doctrine2, on MySQL/Apache) has recently raised interest from the clients and it now needs to be installed on their premises, often a Windows server( arghhh!). That meant we had to make the application compatible with both MySQL and SQL-Server.
Here I summarize the changes and the solutions we adopted.
Continue reading