anklimsk/cakephp-config-plugin

初始化并获取 CakePHP 2.x 插件配置

v1.0.1 2018-11-19 09:16 UTC

This package is auto-updated.

Last update: 2024-09-29 05:21:16 UTC


README

Build Status Coverage Status Latest Stable Version License

初始化并获取插件配置。

此插件提供以下功能

  • 初始化并获取插件配置。

安装

  1. 使用 composer 安装插件: composer require anklimsk/cakephp-config-plugin

  2. 将以下行添加到文件 app/Config/bootstrap.php 的末尾

    CakePlugin::load('CakeConfigPlugin', ['bootstrap' => true]);

使用此插件

  1. 在您的插件 AppModel 模型中包含行为 InitConfig

        public $actsAs = [
            'CakeConfigPlugin.InitConfig' => [
                'pluginName' => 'SomePluginName',
                'checkPath' => 'SomePluginName.param'
            ]
        ];
  2. 在您的插件 Config 目录中创建一个配置文件,例如: somepluginname.php

  3. 填写配置文件,例如。

        $config['SomePluginName'] = [
            'param' => 'value'
            ...
        ];
  4. 如果需要,将配置文件从 'app/Plugin/SomePluginName/Config/somepluginname.php' 复制到 'app/Config',并对其进行编辑。

  5. 如果您需要覆盖应用程序中的配置参数,请使用

    Configure::write('SomePluginName.param', 'newValue');
    
    //  After, in Model call:
    $this->initConfig(true);
  6. 为了初始化插件配置,请使用

    App::uses('InitConfig', 'CakeConfigPlugin.Utility');
    
    $pluginName = 'SomePluginName';
    $checkPath = 'SomePluginName.param';
    $configFile = 'somepluginname';
    $initConfig = new InitConfig($pluginName, $checkPath, $configFile);
    
    $force = false;
    $initConfig->initConfig($force);