![](/img/trans.png)
[英]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.