Reputation: 2520
I've got a form with some display only fields in it. These fields are usually DateTime values... but when empty/null I would like to display the string "never".
EDIT:
To be more explicit: The field should show the DateTime value from the database and if null the string 'never' should be displayed.
How should I do that?
Thanks in advance
Upvotes: 0
Views: 503
Reputation: 5891
You can use Symfony2 Data Transformers :
transform()
function you can check if your date is null
and then return the 'never' string. Otherwise return a string representation of your date. reverseTransform()
function you can check if the string is 'never' and then construct a null
DateTime
object. Otherwise, you transform the given string into a valid DateTime
object with something like 'strtotime()` PHP function.Upvotes: 1