CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 周边产品
  • 旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题(Github)
    • 烘焙
    • 特色资源
    • 培训
    • 聚会
    • 我的CakePHP
    • CakeFest
    • 时事通讯
    • 领英
    • YouTube
    • 脸书
    • 推特
    • 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
    • 路由
    • 测试套件
    • 实用工具
    • 验证
    • 视图

类 CheckHttpCacheComponent

使用 HTTP 缓存头检查是否可以跳过渲染。

检查响应是否可以根据请求头和响应中的缓存头被认为是不同的。如果响应没有被修改,则会跳过控制器和视图渲染过程。客户端将收到一个带有空主体和 "304 Not Modified" 头部的响应。

要使用此组件,您的控制器操作必须设置 Last-Modified 或 Etag 头。如果没有设置其中一个头,此组件将不起作用。

命名空间: Cake\Controller\Component

属性摘要

  • $_config protected
    array<string, mixed>

    运行时配置

  • $_configInitialized protected
    bool

    是否已使用默认值配置了 config 属性

  • $_defaultConfig protected
    array<string, mixed>

    默认配置

  • $_registry protected
    Cake\Controller\ComponentRegistry

    用于延迟加载组件的组件注册类。

  • $componentInstances protected
    array<string,Cake\Controller\Component>

    加载的组件实例。

  • $components protected
    array

    此组件使用的其他组件。

方法摘要

  • __construct() public

    构造函数

  • __debugInfo() public

    返回一个数组,可用于描述此对象的内部状态。

  • __get() public

    用于延迟加载 $components 的魔术方法。

  • _configDelete() protected

    删除单个配置键。

  • _configRead() protected

    读取配置键。

  • _configWrite() protected

    写入配置键。

  • beforeRender() public

    渲染前钩子

  • configShallow() public

    将提供的配置与现有配置合并。与 config()(对嵌套键进行递归合并)不同,此方法执行简单合并。

  • getConfig() public

    返回配置。

  • getConfigOrFail() public

    返回此特定键的配置。

  • getController() public

    获取此组件绑定的控制器。

  • implementedEvents() public

    获取此组件感兴趣的控制器回调。

  • initialize() public

    构造函数钩子方法。

  • log() public

    写入日志消息的便捷方法。有关写入日志的更多信息,请参阅 Log::write()。

  • setConfig() public

    设置配置。

方法详细信息

__construct() ¶ public

__construct(Cake\Controller\ComponentRegistry $registry, array<string, mixed> $config = [])

构造函数

参数
Cake\Controller\ComponentRegistry $registry

此组件可以用来延迟加载其组件的组件注册表。

array<string, mixed> $config optional

配置设置数组。

__debugInfo() ¶ public

__debugInfo(): array<string, mixed>

返回一个数组,可用于描述此对象的内部状态。

返回
array<string, mixed>

__get() ¶ public

__get(string $name): Cake\Controller\Component|null

用于延迟加载 $components 的魔术方法。

参数
string $name

要获取的组件名称。

返回
Cake\Controller\Component|null

_configDelete() ¶ protected

_configDelete(string $key): void

删除单个配置键。

参数
string $key

要删除的键。

返回
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

_configRead() ¶ protected

_configRead(string|null $key): mixed

读取配置键。

参数
string|null $key

要读取的键。

返回
mixed

_configWrite() ¶ protected

_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void

写入配置键。

参数
array<string, mixed>|string $key

要写入的键。

mixed $value

要写入的值。

string|bool $merge optional

True 表示递归合并,'shallow' 表示简单合并,false 表示覆盖,默认为 false。

返回
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

beforeRender() ¶ public

beforeRender(Cake\Event\EventInterfaceCake\Controller\Controller> $event): void

渲染前钩子

参数
Cake\Event\EventInterfaceCake\Controller\Controller> $event

Controller.beforeRender 事件。

返回
void

configShallow() ¶ public

configShallow(array<string, mixed>|string $key, mixed|null $value = null): $this

将提供的配置与现有配置合并。与 config()(对嵌套键进行递归合并)不同,此方法执行简单合并。

设置特定值

$this->configShallow('key', $value);

设置嵌套值

$this->configShallow('some.nested.key', $value);

同时更新多个配置设置

$this->configShallow(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键或完整的配置数组。

mixed|null $value optional

要设置的值。

返回
$this

getConfig() ¶ public

getConfig(string|null $key = null, mixed $default = null): mixed

返回配置。

用法

读取整个配置

$this->getConfig();

读取特定值

$this->getConfig('key');

读取嵌套值

$this->getConfig('some.nested.key');

使用默认值读取

$this->getConfig('some-key', 'default-value');
参数
string|null $key optional

要获取的键或整个配置的 null。

mixed $default optional

键不存在时的返回值。

返回
mixed

getConfigOrFail() ¶ public

getConfigOrFail(string $key): mixed

返回此特定键的配置。

此键的配置值必须存在,绝不能为 null。

参数
string $key

要获取的键。

返回
mixed
抛出
InvalidArgumentException

getController() ¶ public

getController(): Cake\Controller\Controller

获取此组件绑定的控制器。

返回
Cake\Controller\Controller

implementedEvents() ¶ public

implementedEvents(): array<string, mixed>

获取此组件感兴趣的控制器回调。

使用约定将控制器事件映射到标准组件回调方法名称。通过定义其中一个回调方法,假定组件对相关事件感兴趣。

如果您需要添加非约定事件侦听器,或者希望组件侦听非标准事件,请覆盖此方法。

返回
array<string, mixed>

initialize() ¶ public

initialize(array<string, mixed> $config): void

构造函数钩子方法。

实现此方法以避免必须覆盖构造函数并调用父类。

参数
array<string, mixed> $config

提供给此组件的配置设置。

返回
void

log() ¶ public

log(Stringable|string $message, string|int $level = LogLevel::ERROR, array|string $context = []): bool

写入日志消息的便捷方法。有关写入日志的更多信息,请参阅 Log::write()。

参数
Stringable|string $message

日志消息。

string|int $level optional

错误级别。

array|string $context optional

与此消息相关的其他日志数据。

返回
bool

setConfig() ¶ public

setConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this

设置配置。

用法

设置特定值

$this->setConfig('key', $value);

设置嵌套值

$this->setConfig('some.nested.key', $value);

同时更新多个配置设置

$this->setConfig(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键或完整的配置数组。

mixed|null $value optional

要设置的值。

bool $merge 可选

是否递归合并或覆盖现有配置,默认为 true。

返回
$this
抛出
Cake\Core\Exception\CakeException
当尝试设置无效键时。

属性详细信息

$_config ¶ protected

运行时配置

类型
array<string, mixed>

$_configInitialized ¶ protected

是否已使用默认值配置了 config 属性

类型
bool

$_defaultConfig ¶ protected

默认配置

当使用组件时,这些配置会与用户提供的配置进行合并。

类型
array<string, mixed>

$_registry ¶ protected

用于延迟加载组件的组件注册类。

类型
Cake\Controller\ComponentRegistry

$componentInstances ¶ protected

加载的组件实例。

类型
array<string,Cake\Controller\Component>

$components ¶ protected

此组件使用的其他组件。

类型
array
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题(Github)
  • 烘焙
  • 特色资源
  • 培训
  • 聚会
  • 我的CakePHP
  • CakeFest
  • 时事通讯
  • 领英
  • YouTube
  • 脸书
  • 推特
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成