CakePHP
  • 文档
    • 手册
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识 & 商标
  • 商业解决方案
  • 周边商品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • Bakery
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • Linkedin
    • 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
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

命名空间 全局

函数详情

__() ¶

__(string $singular, mixed ...$args): string

如果找到,则返回翻译后的字符串;否则,返回提交的消息。

参数
string $singular

要翻译的文本。

mixed ...$args

带参数的数组或函数中的多个参数。

返回值
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#__

__d() ¶

__d(string $domain, string $msg, mixed ...$args): string

允许您覆盖单个消息查找的当前域。

参数
string $domain

域。

string $msg

要翻译的字符串。

mixed ...$args

带参数的数组或函数中的多个参数。

返回值
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#__d

__dn() ¶

__dn(string $domain, string $singular, string $plural, int $count, mixed ...$args): string

允许您覆盖单个复数消息查找的当前域。返回由 $singular 和 $plural 标识的,来自域 $domain 的计数 $count 的消息的正确复数形式。

参数
string $domain

域。

string $singular

要翻译的单数字符串。

string $plural

复数。

int $count

计数。

mixed ...$args

带参数的数组或函数中的多个参数。

返回值
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#__dn

__dx() ¶

__dx(string $domain, string $context, string $msg, mixed ...$args): string

允许您覆盖单个消息查找的当前域。上下文是翻译字符串的唯一标识符,使其在同一个域内保持唯一性。

参数
string $domain

域。

string $context

文本的上下文。

string $msg

要翻译的字符串。

mixed ...$args

带参数的数组或函数中的多个参数。

返回值
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#__dx

__dxn() ¶

__dxn(string $domain, string $context, string $singular, string $plural, int $count, mixed ...$args): string

返回由 $singular 和 $plural 标识的,针对计数 $count 的消息的正确复数形式。允许您覆盖单个消息查找的当前域。上下文是翻译字符串的唯一标识符,使其在同一个域内保持唯一性。

参数
string $domain

域。

string $context

文本的上下文。

string $singular

要翻译的单数文本。

string $plural

复数文本。

int $count

计数。

mixed ...$args

带参数的数组或函数中的多个参数。

返回值
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#__dxn

__n() ¶

__n(string $singular, string $plural, int $count, mixed ...$args): string

返回由 $singular 和 $plural 标识的,针对计数 $count 的消息的正确复数形式。有些语言对复数消息有不止一种形式,具体取决于计数。

参数
string $singular

要翻译的单数文本。

string $plural

复数文本。

int $count

计数。

mixed ...$args

带参数的数组或函数中的多个参数。

返回值
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#__n

__x() ¶

__x(string $context, string $singular, mixed ...$args): string

如果找到,则返回翻译后的字符串;否则,返回提交的消息。上下文是翻译字符串的唯一标识符,使其在同一个域内保持唯一性。

参数
string $context

文本的上下文。

string $singular

要翻译的文本。

mixed ...$args

带参数的数组或函数中的多个参数。

返回值
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#__x

__xn() ¶

__xn(string $context, string $singular, string $plural, int $count, mixed ...$args): string

返回由 $singular 和 $plural 标识的,针对计数 $count 的消息的正确复数形式。有些语言对复数消息有不止一种形式,具体取决于计数。上下文是翻译字符串的唯一标识符,使其在同一个域内保持唯一性。

参数
string $context

文本的上下文。

string $singular

要翻译的单数文本。

string $plural

复数文本。

int $count

计数。

mixed ...$args

带参数的数组或函数中的多个参数。

返回值
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#__xn

breakpoint() ¶

breakpoint(): string|null

用于在交互式调试器中启动 PsySH 的可评估代码的命令,工作方式与 eval(\Psy\sh()); 相同,您的项目中必须加载 psy/psysh

eval(breakpoint());
返回值
string|null
链接
https://psysh.org/

collection() ¶

collection(iterable $items): Cake\Collection\Collection

返回一个新的 {@link \Cake\Collection\Collection} 对象,包装传入的参数。

参数
iterable $items

用于构建集合的项目。

返回值
Cake\Collection\Collection

dd() ¶

dd(mixed $var, bool|null $showHtml = null): void

打印给定变量的调试信息并退出。

仅在调试模式启用时才运行。否则,它将继续执行代码,并忽略此函数。

参数
mixed $var

要显示调试信息的变量。

bool|null $showHtml 可选

如果设置为 true,则方法以浏览器友好的方式打印调试数据。

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

debug() ¶

debug(mixed $var, bool|null $showHtml = null, bool $showFrom = true): mixed

打印给定变量的调试信息,并返回传入的变量。

仅在调试模式启用时才运行。

参数
mixed $var

要显示调试信息的变量。

bool|null $showHtml 可选

如果设置为 true,则方法以浏览器友好的方式打印调试数据。

bool $showFrom 可选

如果设置为 true,则方法打印函数调用的位置。

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

https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#debug

deprecationWarning() ¶

deprecationWarning(string $version, string $message, int $stackFrame = 1): void

输出弃用警告的辅助方法

参数
string $version

添加此弃用警告的版本。

string $message

要作为弃用警告输出的消息。

int $stackFrame 可选

要包含在错误中的堆栈帧。默认为 1,因为它应该指向应用程序/插件代码。

返回值
void

env() ¶

env(string $key, string|bool|null $default = null): string|float|int|bool|null

从可用来源获取环境变量,并提供对不受支持或不一致的环境变量(例如 IIS 上的 DOCUMENT_ROOT 或 CGI 模式下的 SCRIPT_NAME)的模拟。还公开了一些额外的自定义环境信息。

参数
string $key

环境变量名称。

string|bool|null $default 可选

如果环境变量未定义,请指定默认值。

返回值
string|float|int|bool|null
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#env

h() ¶

h(mixed $text, bool $double = true, string|null $charset = null): mixed

htmlspecialchars 的便捷方法。

参数
mixed $text

要通过 htmlspecialchars 包装的文本。也适用于数组和对象。数组将被映射,并对其所有元素进行转义。如果对象实现了 __toString 方法,则将被字符串转换。否则,将使用类名。其他标量类型将被原样返回。

bool $double 可选

对现有的 html 实体进行编码。

string|null $charset 可选

转义时使用的字符集。默认为 mb_internal_encoding() 中的配置值或 'UTF-8'。

返回值
mixed
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#h

namespaceSplit() ¶

namespaceSplit(string $class): array{0: string, 1: string}

将命名空间从类名中分离。

通常像 list($namespace, $className) = namespaceSplit($class); 这样使用。

参数
string $class

完整的类名,例如 Cake\Core\App。

返回值
array{0: string, 1: string}

pathCombine() ¶

pathCombine(list<string> $parts, bool|null $trailing = null): string

将各个部分使用正斜杠 / 合并。

如果已经存在 / 或 \,则跳过添加正斜杠。

参数
list<string> $parts
bool|null $trailing 可选

确定如何处理尾部斜杠

  • 如果为 true,则确保添加尾部斜杠(如果不存在)
  • 如果为 false,则确保删除任何尾部斜杠
  • 如果为 null,则忽略尾部斜杠
返回值
string

pj() ¶

pj(mixed $var): mixed

JSON 格式化打印的便捷函数。

在终端中,它将类似于直接使用 json_encode() 和 JSON_PRETTY_PRINT,当不在 CLI 上运行时,它还会将 <pre> 标签包装在给定变量的输出周围。类似于 pr()。

此函数返回与传入参数相同的变量。

参数
mixed $var

要打印的变量。

返回值
mixed
另请参阅
pr()
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#pj

pluginSplit() ¶

pluginSplit(string $name, bool $dotAppend = false, string|null $plugin = null): array

将点语法插件名称拆分为其插件和类名称。如果 $name 没有点,则索引 0 将为 null。

常用用法如下

list($plugin, $name) = pluginSplit($name);
参数
string $name

要进行插件拆分的名称。

bool $dotAppend 可选

如果希望插件在末尾添加一个“.”,则将其设置为 true。

string|null $plugin 可选

如果找不到插件,则可选的默认插件,默认为 null。

返回值
array
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#pluginSplit

pr() ¶

pr(mixed $var): mixed

print_r() 的便捷函数。

在终端中,它将类似于直接使用 print_r(),当不在 CLI 上运行时,print_r() 还会将 <pre> 标签包装在给定变量的输出周围。类似于 debug()。

此函数返回与传入参数相同的变量。

参数
mixed $var

要打印的变量。

返回值
mixed
另请参阅
debug()
链接
https://book.cakephp.com.cn/5/en/core-libraries/global-constants-and-functions.html#pr

stackTrace() ¶

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

根据提供的选项输出堆栈跟踪。

选项

  • depth - 要返回的堆栈帧数量。默认为 999
  • args - 是否应显示函数的参数?如果为 true,则将显示每个方法调用的参数。
  • start - 开始生成跟踪的堆栈帧。默认为 1
参数
array<string, mixed> $options 可选

输出堆栈跟踪的格式

返回值
void

triggerWarning() ¶

triggerWarning(string $message): void

触发 E_USER_WARNING。

参数
string $message

警告消息。

返回值
void

url() ¶

url(Psr\Http\Message\UriInterface|array|string|null $url = null, bool $full = false): string

Router::url() 的便捷包装器。

参数
Psr\Http\Message\UriInterface|array|string|null $url 可选

指定以下任何内容的数组:'controller'、'action'、'plugin',此外,您还可以提供路由元素或查询字符串参数。如果为字符串,它可以是任何有效的 url 字符串,也可以是 UriInterface 实例。

bool $full 可选

如果为 true,则完整的基本 URL 将被附加到结果。默认为 false。

返回值
string
抛出
Cake\Core\Exception\CakeException
当找不到路由名称时
另请参阅
\Cake\Routing\Router::url()

urlArray() ¶

urlArray(string $path, array $params = []): array

从路由路径字符串返回数组 URL。

参数
string $path

路由路径。

array $params 可选

指定任何其他参数的数组。也可以是 Router::url() 支持的任何特殊参数。

返回值
array
另请参阅
\Cake\Routing\Router::pathUrl()
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 手册
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识 & 商标
  • 社区
  • 参与
  • 问题 (Github)
  • Bakery
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助 & 支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成