dimti / bettersettings-plugin
具有默认值的 OctoberCMS 设置模型的行为
dev-master
2021-11-14 09:55 UTC
Requires
- composer/installers: ~1.0
This package is not auto-updated.
Last update: 2024-09-30 22:00:11 UTC
README
您喜欢在 OctoberCMS 设置模型中放置数据的位置。
并且您有来自您的网站布局的默认值。
使用此包从设置模型字段中解决默认值
如何使用
首先安装此插件
composer require dimti/bettersettings-plugin
其次 - 在您的设置模型中重新定义行为
更改
Settings extends model { ... public $implement = ['System.Behaviors.SettingsModel']; ... }
为
Settings extends model { ... public $implement = [\Dimti\BetterSettings\Behaviours\BetterSettings::class]; ... }
或为
... use Dimti\BetterSettings\Behaviours\BetterSettings; ... Settings extends model { ... public $implement = [BetterSettings::class]; ... }
并在您的设置模型类中定义变量 $defaults
。
您还可以为更好的可读性定义常量,并在您的 IDE 中使用自动完成
use Dimti\BetterSettings\Behaviours\BetterSettings; class Settings extends Model { const SEZNAM_CID = 'seznam_cid'; const PDF_PHONE_ONE = 'pdf_phone_one'; const PDF_PHONE_TWO = 'pdf_phone_two'; const PDF_PHONE_THREE = 'pdf_phone_three'; public $defaults = [ self::SEZNAM_CID => '100000000', self::PDF_PHONE_ONE => '+420 603 603 603', self::PDF_PHONE_TWO => '+420 723 723 723', ]; public $implement = [BetterSettings::class]; // A unique code public $settingsCode = 'vendor_someplugin_settings'; // Reference to field configuration public $settingsFields = 'fields.yaml'; }