CakePHP
  • 文档
    • 手册
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识与商标
  • 企业解决方案
  • 周边商品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与进来
    • 问题 (Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 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
      • Crypto
      • Exception
    • Validation
    • View

类 Inflector

将英语单词转换为复数和单数形式。

Inflector 将英语名词转换为复数和单数形式。CakePHP 框架中用到的命名约定广泛地使用它。

命名空间: Cake\Utility
链接: https://book.cakephp.com.cn/5/en/core-libraries/inflector.html

属性摘要

  • $_cache protected static
    array<string, mixed>

    方法缓存数组。

  • $_initialState protected static
    array

    Inflector 的初始状态,以便 reset() 起作用。

  • $_irregular protected static
    array<string, string>

    不规则规则

  • $_plural protected static
    array<string, string>

    复数变格规则

  • $_singular protected static
    array<string, string>

    单数变格规则

  • $_uninflected protected static
    list<string>

    不应该变格的词语

方法摘要

  • _cache() protected static

    缓存变格后的值,如果已经存在则返回

  • camelize() public static

    将输入的 lower_case_delimited_string 转换为 CamelCasedString。

  • classify() public static

    返回给定数据库表的单数 CamelCase 变格。(对于表名 "people",返回 "Person")

  • dasherize() public static

    将输入的 CamelCasedString 转换为带有连字符的字符串。

  • delimit() public static

    期望 CamelCasedInputString,并生成 lower_case_delimited_string

  • humanize() public static

    将输入的 lower_case_delimited_string 转换为 "人类可读字符串"。(下划线被替换为空格,并对后面的词语进行首字母大写。)

  • pluralize() public static

    将 $word 转换为复数形式。

  • reset() public static

    清除 Inflectors 变格后的值缓存。并将变格规则重置为初始值。

  • rules() public static

    添加自定义变格 $rules,可以是 'plural'、'singular'、'uninflected' 或 'irregular' $type。

  • singularize() public static

    将 $word 转换为单数形式。

  • tableize() public static

    返回给定模型 $className 的对应表名。(对于类名 "Person",返回 "people")

  • underscore() public static

    将输入的 CamelCasedString 转换为带有下划线的字符串。

  • variable() public static

    返回带有驼峰式的带有下划线的字符串。

方法详情

_cache() ¶ protected static

_cache(string $type, string $key, string|false $value = false): string|false

缓存变格后的值,如果已经存在则返回

参数
string $type

变格类型

string $key

原始值

string|false $value optional

变格后的值

返回
string|false

camelize() ¶ public static

camelize(string $string, string $delimiter = '_'): string

将输入的 lower_case_delimited_string 转换为 CamelCasedString。

参数
string $string

要转换为驼峰式的字符串

string $delimiter optional

输入字符串中的分隔符

返回
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/inflector.html#creating-camelcase-and-under-scored-forms

classify() ¶ public static

classify(string $tableName): string

返回给定数据库表的单数 CamelCase 变格。(对于表名 "people",返回 "Person")

参数
string $tableName

要获取类名的数据库表名

返回
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/inflector.html#creating-table-and-class-name-forms

dasherize() ¶ public static

dasherize(string $string): string

将输入的 CamelCasedString 转换为带有连字符的字符串。

还将下划线替换为连字符

参数
string $string

要转换为带有连字符的字符串。

返回
string

delimit() ¶ public static

delimit(string $string, string $delimiter = '_'): string

期望 CamelCasedInputString,并生成 lower_case_delimited_string

参数
string $string

要进行分隔的字符串

string $delimiter optional

用作分隔符的字符

返回
string

humanize() ¶ public static

humanize(string $string, string $delimiter = '_'): string

将输入的 lower_case_delimited_string 转换为 "人类可读字符串"。(下划线被替换为空格,并对后面的词语进行首字母大写。)

参数
string $string

要转换为人类可读形式的字符串

string $delimiter optional

要替换为空格的字符

返回
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/inflector.html#creating-human-readable-forms

pluralize() ¶ public static

pluralize(string $word): string

将 $word 转换为复数形式。

参数
string $word

单数形式的词语

返回
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/inflector.html#creating-plural-singular-forms

reset() ¶ public static

reset(): void

清除 Inflectors 变格后的值缓存。并将变格规则重置为初始值。

返回
void

rules() ¶ public static

rules(string $type, array $rules, bool $reset = false): void

添加自定义变格 $rules,可以是 'plural'、'singular'、'uninflected' 或 'irregular' $type。

用法

Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
Inflector::rules('irregular', ['red' => 'redlings']);
Inflector::rules('uninflected', ['dontinflectme']);
参数
string $type

变格类型,可以是 'plural'、'singular' 或 'uninflected'。

array $rules

要添加的规则数组。

bool $reset optional

如果为 true,将取消为 $rules 中定义的所有新规则设置默认变格。

返回
void

singularize() ¶ public static

singularize(string $word): string

将 $word 转换为单数形式。

参数
string $word

复数形式的词语

返回
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/inflector.html#creating-plural-singular-forms

tableize() ¶ public static

tableize(string $className): string

返回给定模型 $className 的对应表名。(对于类名 "Person",返回 "people")

参数
string $className

要获取数据库表名的类名

返回
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/inflector.html#creating-table-and-class-name-forms

underscore() ¶ public static

underscore(string $string): string

将输入的 CamelCasedString 转换为带有下划线的字符串。

还将连字符替换为下划线

参数
string $string

要转换为带有下划线的字符串 CamelCasedString

返回
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/inflector.html#creating-camelcase-and-under-scored-forms

variable() ¶ public static

variable(string $string): string

返回带有驼峰式的带有下划线的字符串。

参数
string $string

要转换的字符串。

返回
string
链接
https://book.cakephp.com.cn/5/en/core-libraries/inflector.html#creating-variable-names

属性详情

$_cache ¶ protected static

方法缓存数组。

类型
array<string, mixed>

$_initialState ¶ 受保护 静态

Inflector 的初始状态,以便 reset() 起作用。

类型
array

$_irregular ¶ 受保护 静态

不规则规则

类型
array<string, string>

$_plural ¶ 受保护 静态

复数变格规则

类型
array<string, string>

$_singular ¶ 受保护 静态

单数变格规则

类型
array<string, string>

$_uninflected ¶ 受保护 静态

不应该变格的词语

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

使用 CakePHP API 文档 生成