OctoberCMS - 下拉列表:在下拉列表中按所选名称保存ID

时间:2017-03-03 23:35:09

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

我从十月开始,我也试图创建一个插件,所以也许是noob问题但是在一段时间内无法通过网络搜索找到一个有效的例子并且文档很好作为每个单位,但没有"连接点"恕我直言......我想出了如何使用SimpleTree显示与id相关的相关名称(可能不是正确的方法)。

https://www.screencast.com/t/WDYkfPdMQ https://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

Area.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');
}


}

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

在一段时间内或者至少在我清除缓存的时候我无法创建一条记录,而父母在一段时间后没有返回锁定超时...好吧,等待一些我在300秒后得到超时...增加的id增加这意味着什么东西正在淹没数据库......我怀疑查询是在发送一个字符串,其中需要一个数字,但不知道如何实现...

有人可以提供一些帮助,找到一些相关的例子或snipets或如何???并且可以将相同的结果发送到列表小部件???

TIA

JL

1 个答案:

答案 0 :(得分:0)

好吧,解决了...... 只需挖掘SimpleTree特征代码即可了解其工作原理...... 简单明了......

<?php namespace JML\Gkb\Models;

使用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;
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有关系的列。

如果有人知道答案如何更改&#39; area_id&#39;通过它对Builder的列表小部件的描述,请随时发表评论。

TIA

相关问题