[英]How do I call the value from another backed page form and use it on a component in OctoberCms
[英]How do I use model settings to change my component and page image once at a time? (Octobercms)
我的模型Settings.php
class Settings extends Model
{
public $implement = ['System.Behaviors.SettingsModel'];
// A unique code
public $settingsCode = 'dca_plugins_settings';
// Reference to field configuration
public $settingsFields = 'fields.yaml';
/**
* @var array Relations
*/
public $attachOne = [ 'avatar' => ['System\Models\File'] ];
}
我的Fields.yaml
fields:
id:
label: ID
disabled: true
avatar:
label: Avatar
type: fileupload
mode: image
imageHeight: 150
imageWidth: 250
我的組件comp.php
public $avatar_id = 1;
public function getAvatarImage($avatar_id)
{
$var = \System\Models\File::select('disk_name')->where('attachment_id', $avatar_id)->first();
if (count($var) == 0) return "";
return $var->path;
}
function setMyAvatarId($id)
{
$this->avatar_id = $id;
}
我的html default.htm
{% set avatar_id= __SELF__.property("avatar_id") %}
{% if avatar_id is not empty %}
{% do __SELF__.setMyAvatarId(avatar_id) %}
{% endif %}
<img id="avatar-image" alt="Virtual agent avatar" src="{{ __SELF__.getavatarImage(avatar_id) }}">
<script>
var avatar_id = {{ avatar_id }};
</script>
后端-模型設置
有誰知道如何定義頁面屬性? 如何將頁面鏈接到模型設置?
我該如何運作? 有人請幫助我~~我很迷失:(
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.