Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

HasOneComplexTableField and Booleans


Go to End


3 Posts   1919 Views

Avatar
_Vince

Community Member, 165 Posts

24 July 2009 at 1:36pm

I have a HasOneComplexTableField on a page in the CMS and one of the columns displayed is of type 'Boolean'.

It's saved in the database as either 1 or 0 and it's DISPLAYED as either 1 or 0. Which is fair enough but potentially confusing for the end users.

Is there some way that I can "decode" the 1 and 0 into something like 'Y' and 'N' or whatever?

I only want that for the display.

Avatar
Willr

Forum Moderator, 5523 Posts

24 July 2009 at 2:37pm

Perhaps create a new function (or try overloading your db field in your object). So say your boolean is "HasValue" => "Boolean" you can define something like getHasValueNice() { return ($this->HasValue) ? "Yes" : "No"; } and change your TableField to use HasValueNice rather then HasValue.

You could try overload it by creating a getHasValue() function (same as the dbfield) but not sure if you will run into other issues

Avatar
_Vince

Community Member, 165 Posts

24 July 2009 at 6:51pm

Edited: 24/07/2009 7:26pm

Hey, that sounds interesting. I'll give it a go.

I can just see the end user asking what all those ones and zeros mean and I might as well preempt them. :)

ADDED:

Yup! Works perfectly. Sweet! Thanks!