【问题标题】:October CMS SimpleTree backend form十月 CMS SimpleTree 后端表单
【发布时间】:2018-02-28 03:19:16
【问题描述】:

我正在尝试使用简单树特征来实现父/子关系。

我在documentation 中附加了它的悲伤

在后端,我使用表单构建器添加了一个关系字段以使父元素可选择,即 fields.yaml 文件

fields:
    name:
        label: 'name'
        oc.commentPosition: ''
        span: full
        required: 1
        type: text
    image:
        label: 'image'
        oc.commentPosition: ''
        mode: image
        span: full
        type: mediafinder
    parent_id:
        label: Relation
        oc.commentPosition: ''
        nameFrom: name
        descriptionFrom: description
        span: auto
        type: relation

错误模型不包含 parent_id 的定义。

<?php namespace depcore\parts\Models;
use Model;

/**
 * Model
 */
class Series extends Model
{
    use \October\Rain\Database\Traits\Validation;
    use \October\Rain\Database\Traits\SimpleTree;

    /*
     * Disable timestamps by default.
     * Remove this line if timestamps are defined in the database table.
     */
    public $timestamps = false;

    /*
     * Validation
     */
    public $rules = [
    ];

    /**
     * @var string The database table used by the model.
     */
    public $table = 'depcore_parts_series';

    /**
     * Relations
     */
    public $attachOne = [
      'image' =>'System\Models\File'
    ];

}

我在文档中找不到任何信息如何实现关系,以便用户在添加新元素时可以选择父元素。

【问题讨论】:

    标签: php octobercms octobercms-plugins octobercms-backend


    【解决方案1】:

    好的,所以在挖掘解决方案之后,在模型的后端表单中非常简单,而不是parent_id,该字段应该是parent,所以完整的代码看起来像

    fields:
        name:
            label: 'name'
            oc.commentPosition: ''
            span: full
            required: 1
            type: text
        image:
            label: 'image'
            oc.commentPosition: ''
            mode: image
            span: full
            type: mediafinder
        parent:
            label: 'parent'
            oc.commentPosition: ''
            nameFrom: name
            descriptionFrom: description
            span: auto
            type: relation
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 2017-09-07
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 2018-01-07
      相关资源
      最近更新 更多