Octobercms 过滤器范围选项未从模型返回 class

Octobercms Filter scopes options not returned from model class

根据 Octobercms documentation 我可以从模型 class 方法中获取选项。

但是当我尝试过滤列表时,出现未定义索引错误。

"Undefined index: holiday_type" on line 417 of .../modules/backend/Widgets/Filter.php

我做错了什么?我想通过模型 class

从方法中获取选项

config_filter.yaml

# ===================================
# Filter Scope Definitions
# ===================================

scopes:
    holiday_type:
        label: Holiday Type
        type: group
        conditions: type in (:filtered)
        options: getHolidayTypesAttribute

MyModel.php

public function getHolidayTypesAttribute(){
    return [
        1 => 'default',
        2 => 'new'
    ];
}

您的配置中遗漏了一件事。 :) modelClass

You need to specify which model to use for getting option list if your filter type is group

scopes:
    holiday_type:
        label: Holiday Type
        type: group
        conditions: type in (:filtered)
        options: getHolidayTypesAttribute
        modelClass: Acme\Blog\Models\Category <- you are missing this

Replace Acme\Blog\Models\Category with your model class and try this it should work

如有疑问请评论。