fm-labs / cakephp-settings
此包的最新版本(1.1.1)没有可用的许可信息。
CakePHP 设置插件
1.1.1
2023-03-25 15:25 UTC
Requires
- php: >=8.0
- cakephp/cakephp: ^4.0
Requires (Dev)
README
将配置设置存储在数据库中。
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方式是
$ composer require fm-labs/cakephp-settings
运行迁移
$ ./bin/cake migrations migrate --plugin Settings
使用方法
通过控制台管理设置
// Initialize settings from schema $ ./bin/cake settings init // List available settings $ ./bin/cake settings list // List configured settings values $ ./bin/cake settings values // Get setting value $ ./bin/cake settings get-value // Update setting value $ ./bin/cake settings set-value
通过程序管理设置
@TODO
加载设置
加载您的应用程序的设置
// In your bootstrap.php or in Plugin::bootstrap() \Cake\Core\Configure::load('app', 'settings');
加载插件设置
// In your bootstrap.php or in Plugin::bootstrap() \Cake\Core\Configure::load('PluginName', 'settings');
设置模式文件
应用程序和插件设置定义在设置模式文件中,该文件应在应用程序或插件的配置目录中。分别是 APP/config/settings.php
或 PLUGINS/MyPlugin/config/settings.php
。
<?php // Example settings.php for User plugin return [ 'Settings' => [ 'User' => [ 'groups' => [ 'User.Auth' => ['label' => __('User Authentication')], 'User.Signup' => ['label' => __('User Signup')], ], 'schema' => [ 'User.Login.disabled' => [ 'group' => 'User.Auth', 'type' => 'boolean', 'default' => true, ], 'User.Signup.disabled' => [ 'group' => 'User.Signup', 'type' => 'boolean', 'default' => true, ], 'User.Signup.verifyEmail' => [ 'group' => 'User.Signup', 'type' => 'boolean', 'default' => false, ], ], ], ], ];
事件
当全局设置模式初始化时,将触发 Settings.build
事件。
/** * */ public function implementedEvents() { return [ 'Settings.build' => 'buildSettings', ]; } /** * @param \Cake\Event\Event $event The event object * @param \Settings\Settings $settings The settings object * @return void */ public function buildSettings(Event $event, $settings) { // load a settings schema config file //$settings->load('User.settings'); // add a setting group $settings->addGroup('User.Password', [ 'label' => 'User Password Settings' ]); // add a setting $settings->add('User.Password.expireInDays', [ 'group' => 'User.Password', 'type' => 'int', 'label' => 'Password expiry (in days)', 'help' => 'The password will expire in X days and a new password needs to be entered by the user at the next login.' ]); }