[TYPO3-mvc] Checkbox Viewhelper / boolean

g4-lisz at tonarchiv.ch g4-lisz at tonarchiv.ch
Wed Nov 16 13:25:37 CET 2011


On 16.11.2011 12:56, Lorenz Ulrich wrote:
> Hi everyone
>
> I have setup an Extbase extension (TYPO3 4.6) with the extension 
> builder that contains several boolean checkbox fields. In the 
> database, these booleans are stored as 0 or 1.
>
> Using the checkbox view helper, I would like to offer the possibility 
> to check/uncheck this fields, the current value should be displayed:
>
> <f:form.checkbox property="showEmail1" value="1" />
>
> Now Fluid is complaining about the value of this property:
>
> "Checkbox viewhelpers can only be bound to properties of type boolean 
> or array."
>
> Looking at the ViewHelper, this is clear, since Fluid evaluates the 
> value for boolean but in the database I have 0 or 1 as values.
>
> if (is_bool($propertyValue)) {
>     $checked = $propertyValue === (boolean)$valueAttribute;
> }
>
> How do you handle such problems? The easiest workaround is to typecast 
> the propertyValue before doing the is_bool check but I'm sure I'm not 
> the only one who had this problem.
>
> Thanks for your advice.
>
> Lorenz

hi lorenz

as i understand the viewhelper does not complain about the value type 
but about the type of property.

is showEmail1 defined as boolean in your class definition? getter / 
setter method also?

cheers,
till


More information about the TYPO3-project-typo3v4mvc mailing list