【问题标题】:OctoberCMS - Dropdown : save id by chosen name on dropdownOctoberCMS - 下拉列表:在下拉列表中按所选名称保存 id
【发布时间】:2017-03-03 23:35:09
【问题描述】:

我从 10 月开始,我也在尝试创建一个插件,所以可能是菜鸟问题,但在一段时间内通过网络搜索找不到工作示例,并且文档与每个单元一样好,但缺乏“连接点”恕我直言...我想出了如何使用 SimpleTree 显示与 id 关联的相关名称(可能不是正确的方式)。

https://www.screencast.com/t/WDYkfPdMQhttps://www.screencast.com/t/4NDc3HHDs

frmArea.yaml

fields:
id:
    label: Número
    oc.commentPosition: ''
    span: auto
    disabled: 1
    type: number
area_id:
    label: 'Parente de'
    oc.commentPosition: ''
    emptyOption: 'Sem valor'
    span: auto
    type: dropdown
    nameFrom: area
area:
    label: Área
    span: full
    oc.commentPosition: ''
    type: text

区域.php

<?php namespace JML\Gkb\Models;

use Model;

   /**
 * Model
 */
class Area 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 = 'jml_gkb_areas';

//Relações

public $hasMany = [
    'area_id' => 'JML\Gkb\Models\Area'
];

/*
public $belongsTo = [
    'area_id' => 'JML\Gkb\Models\Area'
]; */

public function getAreaIdOptions(){
    return Area::all()->listsNested('area', 'id');
}


}

如果我创建记录而不选择与父级的任何关系,它们就会被创建(例如图像上的那些)。如果我尝试创建选择父母,它会永远保存...如果我尝试更新 une 记录而不选择父母,那么保存时也会发生同样的情况。

在一段时间内或至少在我清除缓存时,如果父级在一段时间后返回锁定超时,我将无法创建记录......好吧,再等一段时间我会在 300 秒后超时......递增的 id 会递增什么意味着某些东西正在影响数据库...我怀疑查询正在发送一个需要数字的字符串,但不知道如何实现...

有人可以提供一些帮助,了解在哪里可以找到一些相关的示例或片段或如何找到???并且可以对列表小部件实现相同的结果???

TIA

JL

【问题讨论】:

    标签: dropdown octobercms octobercms-plugins october-form-controller


    【解决方案1】:

    嗯,解决了…… 只需挖掘 SimpleTree 特征代码即可了解它的工作原理...... 惊人的简单......

    <?php namespace JML\Gkb\Models;
    

    使用模型;

    /**
     * Model
     */
    class Area 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;
    const PARENT_ID = 'area_id';
    
    
    /*
     * Validation
     */
    public $rules = [
    ];
    
    /**
     * @var string The database table used by the model.
     */
    public $table = 'jml_gkb_areas';
    
    //Relações
    
    public function getAreaIdOptions(){
    
        return Area::all()->listsNested('area', 'id');
    
    }
    
    
    }
    

    只需要删除关系并添加

    const PARENT_ID = 'area_id';
    

    因为那是与 id 有关系的列。

    如果有人知道如何通过 Builder 列表小部件上的描述更改“area_id”的答案,请随时发表评论。

    TIA

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      • 2017-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多