10月CMS SimpleTree后端表单

时间:2017-09-19 11:00:50

标签: php octobercms octobercms-plugins octobercms-backend

我尝试使用Simple Tree Trait实现父/子关系。

我在documentation

中将其作为悲伤附件

在后端,我使用表单生成器添加了relatioship字段以使父元素可选,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'
    ];

}

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

1 个答案:

答案 0 :(得分: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