0

我开始十月,我也尝试创建一个插件,所以也许noob问题,但无法找到一个工作的例子在网上搜索的一些时间和文件是每个单位好,但缺乏“连接点”恕我直言......我想出了如何使用SimpleTree(可能不是正确的方式)显示与id相关的相关名称。OctoberCMS - 下拉菜单:通过下拉列表选择名称保存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 

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


} 

如果我没有选择任何关系父创造的记录,它们会产生(在上的那些图像例如)。如果我尝试创建选择一个父母它会得到永久保存...如果我尝试更新未记录没有父母选择一个父母同样发生时保存。

在一段时间或至少当我清除缓存我不能创造纪录没有父母一段时间后返回锁定超时......好吧,等待更多一些,我得到超时...递增ID获取后经过300秒增加了什么意思是什么东西在打破分贝......我怀疑查询是发送一个字符串在哪里需要一个数字,但不知道如何实现...

有人可以给一些帮助,找到一些相关的例子或snipets或如何?并有可能达到相同的结果,以列表小部件?

TIA

JL

回答

0

好,解决了...... 只是挖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的关系的列。

如果有人知道答案如何改变“AREA_ID”通过它在生成器的列表控件,请随意评论的说明。

TIA