Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php OctoberCMS在列表中显示值可用而不是1,不可用而不是0_Php_Forms_List_Octobercms - Fatal编程技术网

Php OctoberCMS在列表中显示值可用而不是1,不可用而不是0

Php OctoberCMS在列表中显示值可用而不是1,不可用而不是0,php,forms,list,octobercms,Php,Forms,List,Octobercms,我有这个模型: fields.yaml special_offer: label: special_offer type: Switch default: true DB字段为tinyint1 工作很好 但我想在列表中显示的不是0或1,而是可用/不可用。 我可以存储字符串,但我更喜欢转换它 此访问器: public function getSpecialOfferAttribute ($value){ return (

我有这个模型:

 fields.yaml
    special_offer:
        label: special_offer
        type: Switch
        default: true
DB字段为tinyint1

工作很好

但我想在列表中显示的不是0或1,而是可用/不可用。 我可以存储字符串,但我更喜欢转换它

此访问器:

public function getSpecialOfferAttribute ($value){
        return ( $value === 1 ) ? 'available' : 'not available' ;
}
将在列表中显示正确,但在形式上显示错误,因为开关只接受0/1

我该怎么做

谢谢

你可以用一个。在plugin.php文件中定义自定义列类型:

然后在列表列定义文件中使用以下命令:

special_offer:
    label: Special offer
    type: special_offer

那么,这是否意味着我不能使用现有类型来实现它?我只是想使用switch,如果你想要自定义翻译,那么我想你别无选择。该开关使用转换字符串backend::lang.list.column\u switch\u true和backend::lang.list.column\u switch\u false!在10月份的论坛上写的,hope将从Three Thanks获得答案,但是,您仍然可以在fields.yaml上使用开关,并且只更新columns.yaml,这就是该文件的用途
special_offer:
    label: Special offer
    type: special_offer