CakePHP
  • 文档
    • 手册
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 纪念品
  • 自驾游
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (GitHub)
    • 烘焙
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • 领英
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • 帮助与支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • 缓存
    • 集合
    • 命令
    • 控制台
    • 控制器
    • 核心
      • 配置
      • 异常
      • 重试
      • 测试套件
    • 数据库
    • 数据源
    • 错误
    • 事件
    • 表单
    • HTTP
    • 国际化
    • 日志
    • 邮件
    • 网络
    • ORM
    • 路由
    • 测试套件
    • 工具
    • 验证
    • 视图

配置类

配置类。用于管理运行时配置信息。

提供用于读取和写入运行时配置的功能,以及用于加载其他配置文件或存储运行时配置以供将来使用的方法。

命名空间: Cake\Core
链接: https://book.cakephp.com.cn/5/en/development/configuration.html

属性摘要

  • $_engines protected static
    arrayCake\Core\Configure\ConfigEngineInterface>

    配置的引擎类,用于从资源加载配置文件

  • $_hasIniSet protected static
    bool|null

    标志,用于跟踪 ini_set 是否存在。

  • $_values protected static
    array<string, mixed>

    当前存储在 Configure 中的值数组。

方法摘要

  • _getEngine() protected static

    获取配置的引擎。在 `Configure::load()` 和 `Configure::dump()` 中内部使用。如果尚未配置,将为默认值创建新的 PhpConfig。

  • check() public static

    如果 Configure 中设置了给定变量,则返回 true。

  • clear() public static

    清除 Configure 中存储的所有值。

  • config() public static

    向 Configure 添加新的引擎。引擎允许您以各种格式/存储位置读取配置文件。CakePHP 带有两个内置引擎 PhpConfig 和 IniConfig。您也可以在应用程序中实现自己的引擎类。

  • configured() public static

    获取已配置的引擎对象名称。

  • consume() public static

    用于从 Configure 中读取和删除变量。

  • consumeOrFail() public static

    用于使用 Configure 中存储的信息。无法在 Configure 中存储 `null` 值。

  • delete() public static

    用于从 Configure 中删除变量。

  • drop() public static

    删除配置的引擎。这将取消设置引擎,并使任何未来尝试使用它都会导致异常。

  • dump() public static

    将 Configure 中当前的数据转储到 $key 中。序列化格式由作为 $config 附加的配置引擎决定。例如,如果“default”适配器是 PhpConfig,则生成的将是一个可以由 PhpConfig 加载的 PHP 配置文件。

  • isConfigured() public static

    如果配置了引擎对象,则返回 true。

  • load() public static

    从资源加载存储的配置信息。您可以使用 `Configure::config()` 添加配置文件资源引擎。

  • read() public static

    用于读取存储在 Configure 中的信息。无法在 Configure 中存储 `null` 值。

  • readOrFail() public static

    用于获取存储在 Configure 中的信息。无法在 Configure 中存储 `null` 值。

  • restore() public static

    将存储在缓存中的配置数据还原到配置中。还原的值将覆盖现有的值。

  • store() public static

    用于将运行时配置写入缓存。可以使用 `Configure::restore()` 还原存储的运行时配置。这些方法可用于启用配置管理器前端或其他 GUI 类型的配置界面。

  • version() public static

    用于确定当前的 CakePHP 版本。

  • write() public static

    用于在 Configure 中存储动态变量。

方法详细说明

_getEngine() ¶ protected static

_getEngine(string $config): Cake\Core\Configure\ConfigEngineInterface|null

获取配置的引擎。在 `Configure::load()` 和 `Configure::dump()` 中内部使用。如果尚未配置,将为默认值创建新的 PhpConfig。

参数
string $config

配置的适配器名称

返回值
Cake\Core\Configure\ConfigEngineInterface|null

check() ¶ public static

check(string $var): bool

如果 Configure 中设置了给定变量,则返回 true。

参数
string $var

要检查的变量名

返回值
bool

clear() ¶ public static

clear(): void

清除 Configure 中存储的所有值。

返回值
void

config() ¶ public static

config(string $name, Cake\Core\Configure\ConfigEngineInterface $engine): void

向 Configure 添加新的引擎。引擎允许您以各种格式/存储位置读取配置文件。CakePHP 带有两个内置引擎 PhpConfig 和 IniConfig。您也可以在应用程序中实现自己的引擎类。

要向 Configure 添加新的引擎

Configure::config('ini', new IniConfig());
参数
string $name

正在配置的引擎名称。此别名稍后用于从特定引擎读取值。

Cake\Core\Configure\ConfigEngineInterface $engine

要附加的引擎。

返回值
void

configured() ¶ public static

configured(): list<string>

获取已配置的引擎对象名称。

返回值
list<string>

consume() ¶ public static

consume(string $var): mixed

用于从 Configure 中读取和删除变量。

这主要用于引导期间将配置数据从配置移到 CakePHP 中的各种其他类中。

参数
string $var

要读取和删除的键。

返回值
mixed

consumeOrFail() ¶ public static

consumeOrFail(string $var): mixed

用于使用 Configure 中存储的信息。无法在 Configure 中存储 `null` 值。

作为 Configure::consume() 和 Configure::check() 的包装器。通过此方法使用的配置键值对应该存在。如果它不存在,将抛出异常。

参数
string $var

要使用的变量。使用“.”访问数组元素。

返回值
mixed
抛出
Cake\Core\Exception\CakeException
如果未设置请求的配置。

delete() ¶ public static

delete(string $var): void

用于从 Configure 中删除变量。

用法

Configure::delete('Name'); will delete the entire Configure::Name
Configure::delete('Name.key'); will delete only the Configure::Name[key]
参数
string $var

要删除的 var

返回值
void
链接
https://book.cakephp.com.cn/5/en/development/configuration.html#deleting-configuration-data

drop() ¶ public static

drop(string $name): bool

删除配置的引擎。这将取消设置引擎,并使任何未来尝试使用它都会导致异常。

参数
string $name

要删除的引擎名称。

返回值
bool

dump() ¶ public static

dump(string $key, string $config = 'default', list<string> $keys = []): bool

将 Configure 中当前的数据转储到 $key 中。序列化格式由作为 $config 附加的配置引擎决定。例如,如果“default”适配器是 PhpConfig,则生成的将是一个可以由 PhpConfig 加载的 PHP 配置文件。

用法

假设“default”引擎是 PhpConfig 的实例。将 Configure 中的所有数据保存到文件 `my_config.php` 中

Configure::dump('my_config', 'default');

仅保存错误处理配置

Configure::dump('error', 'default', ['Error', 'Exception'];
参数
string $key

要在配置适配器中创建的标识符。这可以是文件名或缓存键,具体取决于使用的适配器。

string $config optional

要使用其转储数据的配置适配器名称。

list<string> $keys optional

要转储的顶级键的名称。这允许您仅保存存储在 Configure 中的一些数据。

返回值
bool
抛出
Cake\Core\Exception\CakeException
如果适配器没有实现 `dump` 方法。

isConfigured() ¶ public static

isConfigured(string $name): bool

如果配置了引擎对象,则返回 true。

参数
string $name

引擎名称。

返回值
bool

load() ¶ public static

load(string $key, string $config = 'default', bool $merge = true): bool

从资源加载存储的配置信息。您可以使用 `Configure::config()` 添加配置文件资源引擎。

加载的配置信息将与当前运行时配置合并。您可以通过在文件名之前加上插件名称来加载插件中的配置文件。

Configure::load('Users.user', 'default')

将使用默认配置引擎加载“user”配置文件。您可以通过提供要加载的资源的名称来加载应用程序配置文件。

Configure::load('setup', 'default');

如果使用 `default` 配置且尚未为其配置引擎,则将使用 PhpConfig 自动创建一个引擎。

参数
string $key

要加载的配置资源的名称。

string $config optional

用于读取由 $key 标识的资源的已配置引擎的名称。

bool $merge 可选

如果配置文件应该合并而不是简单地覆盖。

返回值
bool
抛出
Cake\Core\Exception\CakeException
如果找不到 $config 引擎。
链接
https://book.cakephp.com.cn/5/en/development/configuration.html#reading-and-writing-configuration-files

read() ¶ public static

read(string|null $var = null, mixed $default = null): mixed

用于读取存储在 Configure 中的信息。无法在 Configure 中存储 `null` 值。

用法

Configure::read('Name'); will return all values for Name
Configure::read('Name.key'); will return only the value of Configure::Name[key]
参数
string|null $var 可选

要获取的变量。使用“.”来访问数组元素。

mixed $default 可选

当配置不存在时的返回值。

返回值
mixed
链接
https://book.cakephp.com.cn/5/en/development/configuration.html#reading-configuration-data

readOrFail() ¶ public static

readOrFail(string $var): mixed

用于获取存储在 Configure 中的信息。无法在 Configure 中存储 `null` 值。

充当 Configure::read() 和 Configure::check() 的包装器。通过此方法获取的配置键值对应该存在。如果不存在,将抛出异常。

用法

Configure::readOrFail('Name'); will return all values for Name
Configure::readOrFail('Name.key'); will return only the value of Configure::Name[key]
参数
string $var

要获取的变量。使用“.”来访问数组元素。

返回值
mixed
抛出
Cake\Core\Exception\CakeException
如果未设置请求的配置。
链接
https://book.cakephp.com.cn/5/en/development/configuration.html#reading-configuration-data

restore() ¶ public static

restore(string $name, string $cacheConfig = 'default'): bool

将存储在缓存中的配置数据还原到配置中。还原的值将覆盖现有的值。

参数
string $name

要加载的存储配置文件的名称。

string $cacheConfig 可选

要从中读取的缓存配置的名称。

返回值
bool

store() ¶ public static

store(string $name, string $cacheConfig = 'default', array|null $data = null): bool

用于将运行时配置写入缓存。可以使用 `Configure::restore()` 还原存储的运行时配置。这些方法可用于启用配置管理器前端或其他 GUI 类型的配置界面。

参数
string $name

保存的配置的存储名称。

string $cacheConfig 可选

要保存到的缓存配置。默认为“default”。

array|null $data 可选

要存储的数据数组,或保留为空以存储所有值。

返回值
bool

version() ¶ public static

version(): string

用于确定当前的 CakePHP 版本。

用法

Configure::version();
返回值
string

write() ¶ public static

write(array<string, mixed>|string $config, mixed $value = null): void

用于在 Configure 中存储动态变量。

用法

Configure::write('One.key1', 'value of the Configure::One[key1]');
Configure::write(['One.key1' => 'value of the Configure::One[key1]']);
Configure::write('One', [
    'key1' => 'value of the Configure::One[key1]',
    'key2' => 'value of the Configure::One[key2]'
]);

Configure::write([
    'One.key1' => 'value of the Configure::One[key1]',
    'One.key2' => 'value of the Configure::One[key2]'
]);
参数
array<string, mixed>|string $config

要写入的键,可以是点符号表示的值。或者可以是包含键和值的数组。

mixed $value 可选

为给定键设置的值。

返回值
void
链接
https://book.cakephp.com.cn/5/en/development/configuration.html#writing-configuration-data

属性详细说明

$_engines ¶ protected static

配置的引擎类,用于从资源加载配置文件

类型
arrayCake\Core\Configure\ConfigEngineInterface>

$_hasIniSet ¶ protected static

标志,用于跟踪 ini_set 是否存在。

类型
bool|null

$_values ¶ protected static

当前存储在 Configure 中的值数组。

类型
array<string, mixed>
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 手册
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题 (GitHub)
  • 烘焙
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • 领英
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助与支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成