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