对于布尔字段,摘要默认将值显示为0或1 ...
class MyDataObject extends DataObject {
private static $db = array(
'Name' => 'Varchar(255)',
'MyBoolean' => 'Boolean',
);
public static $summary_fields = array (
'Name',
'MyBoolean',
);
}
......我知道如何使用强制转换将其更改为是或否...
class MyDataObject extends DataObject {
private static $db = array(
'Name' => 'Varchar(255)',
'MyBoolean' => 'Boolean',
);
public static $casting = array (
'MyBooleanText' => 'Text',
);
public function MyBooleanText() {
return $this->MyBoolean ? 'Yes' : 'No';
}
public static $summary_fields = array (
'Name',
'MyBooleanText',
);
}
...但是我的问题是如何默认更改每个值以在摘要行中显示它而不必为每个对象设置转换?
答案 0 :(得分:1)
在你的$summary_fields
中你只需要将.Nice
方法添加到你的布尔值。
E.g:
class MyDataObject extends DataObject {
static $db = array(
'Name' => 'Varchar(255)',
'MyBoolean' => 'Boolean',
);
public static $summary_fields = array (
'Name' => 'Name',
'MyBoolean.Nice' => 'MyBoolean',
);
}