【问题标题】:OcotberCMS PivotModel $attachOne relationOctoberCMS 枢轴模型 $attachIng 关系
【发布时间】:2021-08-25 08:30:13
【问题描述】:

我正在尝试使用OcotberCMS 中的文件附件枢轴创建many-to-many 关系。

这是我的关系

public $belongsToMany = [
    'users' => [
        User::class,
        'key' => 'task_id',
        'otherKey' => 'user_id',
        'table' => 'tasks_users',
        'pivot' => ['status'],
        'pivotModel' => TaskUser::class
    ]
];

在我的 pivotModel 中

class TaskUser extends Pivot
...
public $attachOne = [
    'file' => ['System\Models\File']
];

YAML 配置

pivot:
    form:
        tabs:
            fields:
                pivot[file]:
                    label: Image
                    type: fileupload
                    mode: image
                    span: left
                    tab: Image

表单已正确呈现,但尝试上传文件时,抛出错误: Upload error "A widget with class name 'relationUsersManagePivotFormPivotFile' has not been bound to the controller" on line 605 of D:\Projects\esport\modules\backend\classes\Controller.php

【问题讨论】:

    标签: php model-view-controller yaml relationship octobercms


    【解决方案1】:

    似乎关系管理器无法处理大量嵌套。同样,File 在枢轴模态中使用时也不能与 differed binding 一起使用。

    不支持具有differed binding 透视数据的关系管理器 参考:https://octobercms.com/docs/backend/relations#belongs-to-many-pivot

    所以也许我们可以使用另一种方式。如果可以的话。

    1. 在数据透视表中,您可以使用text type 添加新字段file
    2. 在关系配置中指定它 => 'pivot' => ['status', 'file']

    现在来自外地

    pivot:
        form:
            fields:
                pivot[value]:
                    label: Value
                    type: text
                pivot[file]:
                    label: Picture
                    type: mediafinder                    
    

    现在您可以上传和选择文件或选择现有文件。它们将被存储为file path,因此可以直接访问。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 2018-11-22
      • 1970-01-01
      • 2019-07-05
      • 2021-01-07
      相关资源
      最近更新 更多