21282 Posts in 5730 Topics by 2601 members
General Questions
SilverStripe Forums » General Questions » showing Boolean Value as YES or NO in Complex Table Field
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1174 Views |
-
showing Boolean Value as YES or NO in Complex Table Field

6 January 2011 at 6:36pm
Hi
Stupid question - what is the easiest way to show a Boolean Value as YES / NO rather than 1 or 0 in a Complex Table Field????
Thank you
Nicolaas
-
Re: showing Boolean Value as YES or NO in Complex Table Field

7 January 2011 at 1:17pm
I'd use casting... like this...
class MyObject extends DataObject
{
static $db = array(
'MyBool' => 'Boolean',
);
public static $summary_fields = array (
'MyBoolText' => 'YesNo'
);
static $casting = array(
'MyBoolText' => 'Text',
);
public function MyBoolText(){
return $this->MyBool ? 'Yes' : 'No';
}
} -
Re: showing Boolean Value as YES or NO in Complex Table Field

15 June 2012 at 9:59pm
works. many thanks
-
Re: showing Boolean Value as YES or NO in Complex Table Field

22 June 2012 at 9:39am
I think it's possible to use $SomeField.Nice
-
Re: showing Boolean Value as YES or NO in Complex Table Field

22 June 2012 at 9:06pm Last edited: 22 June 2012 9:07pm
Yes, you are probably right.
I think you need to use this:
table = ComplexTableField....
$table->setFieldCasting(array(
'MyBooleanField' => 'Boolean->Nice',
'Total' => 'Currency->Nice'
)); -
Re: showing Boolean Value as YES or NO in Complex Table Field

22 June 2012 at 9:13pm
ok, so the question then is, how can we set these formatting rules for the summary_fields....
-
Re: showing Boolean Value as YES or NO in Complex Table Field

23 June 2012 at 7:55am
I think this will work...
static $db = array(
'myBool' => 'Boolean'
);static $summary_fields = array(
'myBool'
);public function myBool(){
return ($this->myBool==true ? 'Yes':'No');
}It should then show Yes/No instead of 1/0.
| 1174 Views | ||
|
Page:
1
|
Go to Top |



