O'Reilly logo

Extending Symfony2 Web Application Framework by Sébastien Armand

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Data transformers

By using data transformers, the form components in Symfony offer a powerful way of dealing with this scenario. The form component allows three distinct representations of the same data, which are as follows:

  • The one in the view (in the HTML)
  • The one in the model
  • The one in the form itself (if necessary)

In most cases, this is overkill. For our current case, only one transformer will be enough to go from a string (such as 42.0321650 and 115.032160513) to the PHP object representation. However, if you think about date and time, it can be that your form offers the choice that the view shows three select boxes for the year, month, and day; a datepicker; or a timestamp-based value. At the same time, you can expect that your PHP model ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required