CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 纪念品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与其中
    • 问题 (Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • 领英
    • 优酷
    • 脸书
    • 推特
    • Mastodon
    • 帮助与支持
    • 论坛
    • 堆栈溢出
    • 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
      • 客户端
      • Cookie
      • 异常
      • 中间件
      • 会话
      • 测试套件
    • 国际化
    • 日志
    • 邮件
    • 网络
    • ORM
    • 路由
    • 测试套件
    • 工具
    • 验证
    • 视图

类 FlashMessage

FlashMessage 类提供了一种将闪存变量写入会话的方法,以便通过 FlashHelper 在视图中呈现。

命名空间: Cake\Http

属性摘要

  • $_config protected
    array<string, mixed>

    运行时配置

  • $_configInitialized protected
    bool

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

  • $_defaultConfig protected
    array<string, mixed>

    默认配置

  • $session protected
    Cake\Http\Session

方法摘要

  • __construct() public

    构造函数

  • _configDelete() protected

    删除单个配置键。

  • _configRead() protected

    读取配置键。

  • _configWrite() protected

    写入配置键。

  • configShallow() public

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

  • consume() public

    获取给定键的消息并从会话中移除。

  • error() public

    设置成功消息。

  • getConfig() public

    返回配置。

  • getConfigOrFail() public

    返回此特定键的配置。

  • info() public

    设置信息消息。

  • set() public

    存储可以在视图中输出的闪存消息。

  • setConfig() public

    设置配置。

  • setExceptionMessage() public

    将异常的消息设置为闪存消息。

  • success() public

    设置成功消息。

  • warning() public

    设置警告消息。

方法详细说明

__construct() ¶ public

__construct(Cake\Http\Session $session, array<string, mixed> $config = [])

构造函数

参数
Cake\Http\Session $session

会话实例。

array<string, mixed> $config optional

配置数组。

另请参阅
FlashMessage::set() 有关有效配置键的列表。

_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
如果尝试覆盖现有的配置

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

consume() ¶ public

consume(string $key): array|null

获取给定键的消息并从会话中移除。

参数
string $key

获取消息的键。

返回值
array|null

error() ¶ public

error(string $message, array<string, mixed> $options = []): void

设置成功消息。

'element' 选项将设置为 'error'。

参数
string $message

要闪存的消息。

array<string, mixed> $options optional

选项数组。

返回值
void
另请参阅
FlashMessage::set() 有关有效选项的列表

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

info() ¶ public

info(string $message, array<string, mixed> $options = []): void

设置信息消息。

'element' 选项将设置为 'info'。

参数
string $message

要闪存的消息。

array<string, mixed> $options optional

选项数组。

返回值
void
另请参阅
FlashMessage::set() 有关有效选项的列表

set() ¶ public

set(string $message, array<string, mixed> $options = []): void

存储可以在视图中输出的闪存消息。

如果连续调用此方法,消息将堆叠(如果它们使用相同的闪存键设置)。

选项

  • key 要在会话的 Flash 键下设置的键。
  • element 用于呈现闪存消息的元素。您可以使用 'SomePlugin.name' 样式的值来获取插件中的闪存元素。
  • plugin 要从中使用元素的插件名称。
  • params 要使元素可用的变量数组。
  • clear 一个布尔值,表示当前堆栈是否应该被清除以开始一个新的堆栈。
  • escape 设置为 false 以允许模板打印 HTML 内容。
参数
string $message

要闪存的消息。

array<string, mixed> $options optional

选项数组

返回值
void
另请参阅
FlashMessage::$_defaultConfig 有关选项的默认值的说明。

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 optional

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

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

setExceptionMessage() ¶ public

setExceptionMessage(Throwable $exception, array<string, mixed> $options = []): void

将异常的消息设置为闪存消息。

如果未设置,以下选项将默认设置

'element' => 'error',
`params' => ['code' => $exception->getCode()]
参数
Throwable $exception

异常实例。

array<string, mixed> $options optional

选项数组。

返回值
void
另请参阅
FlashMessage::set() 有关有效选项的列表

success() ¶ public

success(string $message, array<string, mixed> $options = []): void

设置成功消息。

'element' 选项将设置为 'success'。

参数
string $message

要闪存的消息。

array<string, mixed> $options optional

选项数组。

返回值
void
另请参阅
FlashMessage::set() 有关有效选项的列表

warning() ¶ public

warning(string $message, array<string, mixed> $options = []): void

设置警告消息。

'element' 选项将设置为 'warning'。

参数
string $message

要闪存的消息。

array<string, mixed> $options optional

选项数组。

返回值
void
另请参阅
FlashMessage::set() 有关有效选项的列表

属性详细说明

$_config ¶ protected

运行时配置

类型
array<string, mixed>

$_configInitialized ¶ protected

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

类型
bool

$_defaultConfig ¶ protected

默认配置

类型
array<string, mixed>

$session ¶ protected

类型
Cake\Http\Session
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与其中
  • 问题 (Github)
  • 烘焙坊
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • 领英
  • 优酷
  • 脸书
  • 推特
  • Mastodon
  • 帮助与支持
  • 论坛
  • 堆栈溢出
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成