【问题标题】:Octobercms Filter scopes options not returned from model class模型类未返回 Octobercms 过滤器范围选项
【发布时间】:2020-03-11 13:28:39
【问题描述】:

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

但是当我尝试过滤列表时,我得到一个未定义的索引错误。

.../modules/backend/Widgets/Filter.php 第 417 行的“未定义索引:holiday_type”

我做错了什么?我想通过模型类从方法中获取选项

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'
    ];
}

【问题讨论】:

    标签: backend octobercms octobercms-backend


    【解决方案1】:

    您的配置中缺少一件事。 :) modelClass

    如果您的过滤器类型为group,您需要指定用于获取选项列表的模型

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

    your model class 替换 Acme\Blog\Models\Category 并尝试它应该可以工作

    如有任何疑问,请发表评论。

    【讨论】:

    • 哦,是的,这就是问题所在。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    • 1970-01-01
    • 2015-07-17
    相关资源
    最近更新 更多