首页 文章

OctoberCMS columns.yaml VALUE FROM包含多个字段

提问于
浏览
0

我在 OctoberCMS 中使用 Builder 插件创建了一个插件,其中我有 columns.yaml 文件 .

在一个名为 property_id 的字段中,我有一个字段 VALUE FROM ,它要求添加我的表的字段名称,因此我添加了一个名为 street_number 的字段 .

但我想在那里连接多个字段 . 像下面的东西 .

CONCAT(street_number, ' ', address)

但这不起作用 . 我也试过其他方式,但它仍然无法正常工作 .

有人可以指导我如何实现这一目标吗?

此外,如果这些字段在表中存在各自的值,则会很好 .

这就是我的 columns.yaml 文件的样子 .

columns:
    property_id:
        label: Property
        type: text
        searchable: true
        sortable: false
        relation: Property
        valueFrom: street_number
    start_datetime:
        label: 'Start Date Time'
        type: datetime
        searchable: true
        sortable: true
    end_datetime:
        label: 'End Date Time'
        type: datetime
        searchable: true
        sortable: true
    status:
        label: Status
        type: number
        searchable: true
        sortable: true
        select: 'CASE WHEN (status =  ''1'' ) THEN ''Active'' ELSE ''Inactive'' END'

谢谢

2 回答

  • 1

    由于这里涉及逻辑,您可能只想使用自定义列类型,如https://octobercms.com/docs/backend/lists#custom-column-types所述 . 我不想在yaml文件中放入太多逻辑 .

    编辑

    OP添加了一些示例代码,以准确显示我在上面的评论here中提到的内容 .

  • 2

    好,朋友们,

    我已经想出了一个解决方案,感谢suggestion link上面的suggestion link . 以下是我为实现这一目标所做的工作 .

    更新了 columns.yaml 文件中的以下代码块 .

    columns:
        property_id:
            label: Property
            type: property_details
            searchable: true
            sortable: false
            relation: Property
    

    在这里添加 type: property_details .

    打开并更新了我的 Plugin.php 文件并添加了以下行 .

    <?php namespace Technobrave\Homeopenintegration;
    
    use System\Classes\PluginBase;
    
    
    use technobrave\Properties\Models\Property as Property;
    
    
    class Plugin extends PluginBase
    {
    
    
        public function registerListColumnTypes()
            {
    
                return [
                    // A local method, i.e $this->evalUppercaseListColumn()
                    'property_details' => [$this, 'evalPropertyDetailsListColumn'],        
                ];
            }
    
    
        public function evalPropertyDetailsListColumn($value, $column, $record)
        {
            $current_property = Property::where('id', $record->property_id)->first();
            return $current_property->lot;
    
        }
    }
    

    感谢您的努力和帮助 .

相关问题