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
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget

TextHelper 类

文本助手库。

文本操作:突出显示、摘录、截断、去除链接、将电子邮件地址转换为 mailto: 链接...

命名空间: Cake\View\Helper
参见: \Cake\Utility\Text
链接: https://book.cakephp.com.cn/5/en/views/helpers/text.html

属性摘要

  • $Html public @property
    Cake\View\Helper\HtmlHelper
  • $_View protected
    Cake\View\View

    此助手所附加的 View 实例

  • $_config protected
    array<string, mixed>

    运行时配置

  • $_configInitialized protected
    bool

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

  • $_defaultConfig protected
    array<string, mixed>

    此助手的默认配置。

  • $_placeholders protected
    array<string, array>

    哈希及其内容的数组。在将链接插入文本时使用。

  • $helperInstances protected
    array<string,Cake\View\Helper>

    加载的助手实例。

  • $helpers protected
    array

    助手

方法摘要

  • __call() public

    调用 String 实用程序类中的方法

  • __construct() public

    默认构造函数

  • __debugInfo() public

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

  • __get() public

    延迟加载助手。

  • _configDelete() protected

    删除单个配置键。

  • _configRead() protected

    读取配置键。

  • _configWrite() protected

    写入配置键。

  • _confirm() protected

    返回一个字符串,用作确认对话框的 onclick 处理程序。

  • _insertPlaceHolder() protected

    保存字符串的占位符,以便以后使用。这可以避免在 URL 中双重转义内容。

  • _linkEmails() protected

    链接电子邮件地址

  • _linkUrls() protected

    将占位符替换为链接。

  • _prepareLinkLabel() protected

    准备链接标签。

  • addClass() public

    将给定的类添加到元素选项中

  • autoLink() public

    将所有链接和电子邮件地址转换为 HTML 链接。

  • autoLinkEmails() public

    在给定的文本中添加电子邮件链接(<a href="mailto:....")。

  • autoLinkUrls() public

    在给定的文本中添加链接(<a href=....) ,方法是查找以字符串(如 http:// 和 ftp://)开头的文本。

  • autoParagraph() public

    为给定文本中的所有换行符格式化段落
    为单行返回添加

    为双行返回添加

  • configShallow() public

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

  • excerpt() public @method

    参见 Text::excerpt()

  • getConfig() public

    返回配置。

  • getConfigOrFail() public

    返回此特定键的配置。

  • getView() public

    获取此助手绑定的 View 实例。

  • highlight() public @method

    参见 Text::highlight()

  • implementedEvents() public

    事件监听器。

  • initialize() public

    构造函数钩子方法。

  • setConfig() public

    设置配置。

  • slug() public @method

    参见 Text::slug()

  • tail() public @method

    参见 Text::tail()

  • toList() public @method

    参见 Text::toList()

  • truncate() public @method

    参见 Text::truncate()

方法详情

__call() ¶ public

__call(string $method, array $params): mixed

调用 String 实用程序类中的方法

参数
string $method

要调用的方法

array $params

方法的参数数组。

返回
mixed

__construct() ¶ public

__construct(Cake\View\View $view, array<string, mixed> $config = [])

默认构造函数

参数
Cake\View\View $view

此助手所附加的 View。

array<string, mixed> $config optional

助手的配置设置。

__debugInfo() ¶ public

__debugInfo(): array<string, mixed>

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

返回
array<string, mixed>

__get() ¶ public

__get(string $name): Cake\View\Helper|null

延迟加载助手。

参数
string $name

正在访问的属性的名称。

返回
Cake\View\Helper|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
如果尝试覆盖现有配置

_confirm() ¶ protected

_confirm(string $okCode, string $cancelCode): string

返回一个字符串,用作确认对话框的 onclick 处理程序。

参数
string $okCode

用户选择“确定”后要执行的代码

string $cancelCode

用户选择“取消”后要执行的代码

返回
string

_insertPlaceHolder() ¶ protected

_insertPlaceHolder(array $matches): string

保存字符串的占位符,以便以后使用。这可以避免在 URL 中双重转义内容。

参数
array $matches

正则表达式匹配的数组。

返回
string

_linkEmails() ¶ protected

_linkEmails(string $text, array<string, mixed> $options): string

链接电子邮件地址

参数
string $text

要操作的文本

array<string, mixed> $options

要用于 HTML 的选项数组。

返回
string
另请参见
\Cake\View\Helper\TextHelper::autoLinkEmails()

_linkUrls() ¶ protected

_linkUrls(string $text, array<string, mixed> $htmlOptions): string

将占位符替换为链接。

参数
string $text

要操作的文本。

array<string, mixed> $htmlOptions

生成的链接的选项。

返回
string

_prepareLinkLabel() ¶ protected

_prepareLinkLabel(string $name, array $options): string

准备链接标签。

参数
string $name

链接标签。

array $options

<string, mixed> $htmlOptions 生成的链接标签的选项。

返回
string

addClass() ¶ public

addClass(array<string, mixed> $options, string $class, string $key = 'class'): array<string, mixed>

将给定的类添加到元素选项中

参数
array<string, mixed> $options

要添加类的数组选项/属性

string $class

要添加的类名。

string $key optional

要用于类的键。默认为 'class'。

返回
array<string, mixed>

autoLink() ¶ public

autoLink(string $text, array<string, mixed> $options = []): string

将所有链接和电子邮件地址转换为 HTML 链接。

选项

  • escape 控制输入的 HTML 转义。默认为 true。
参数
string $text

文本

array<string, mixed> $options 可选

HTML 选项数组,以及上面列出的选项。

返回
string
链接
https://book.cakephp.com.cn/5/en/views/helpers/text.html#linking-both-urls-and-email-addresses

autoLinkEmails() ¶ public

autoLinkEmails(string $text, array<string, mixed> $options = []): string

在给定的文本中添加电子邮件链接(<a href="mailto:....")。

选项

  • escape 控制输入的 HTML 转义。默认为 true。
参数
string $text

文本

array<string, mixed> $options 可选

HTML 选项数组,以及上面列出的选项。

返回
string
链接
https://book.cakephp.com.cn/5/en/views/helpers/text.html#linking-email-addresses

autoLinkUrls() ¶ public

autoLinkUrls(string $text, array<string, mixed> $options = []): string

在给定的文本中添加链接(<a href=....) ,方法是查找以字符串(如 http:// 和 ftp://)开头的文本。

选项

  • escape 控制输入的 HTML 转义。默认为 true。
  • stripProtocol 从链接开头去除 http:// 和 https://。默认关闭。
  • maxLength 链接标签的最大长度。默认关闭。
  • ellipsis 附加到链接标签末尾的字符串。默认为 UTF8 版本。
参数
string $text

文本

array<string, mixed> $options 可选

HTML 选项数组,以及上面列出的选项。

返回
string
链接
https://book.cakephp.com.cn/5/en/views/helpers/text.html#linking-urls

autoParagraph() ¶ public

autoParagraph(string|null $text): string

为给定文本中的所有换行符格式化段落
为单行返回添加

为双行返回添加

参数
string|null $text

文本

返回
string
链接
https://book.cakephp.com.cn/5/en/views/helpers/text.html#converting-text-into-paragraphs

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 可选

要设置的值。

返回
$this

excerpt() ¶ public @method

excerpt(string $text, string $phrase, int $radius = 100, string $ending = '…'): string

参见 Text::excerpt()

参数
string $text
string $phrase
int $radius 可选
string $ending 可选
返回
string

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 可选

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

mixed $default 可选

键不存在时的返回值。

返回
mixed

getConfigOrFail() ¶ public

getConfigOrFail(string $key): mixed

返回此特定键的配置。

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

参数
string $key

要获取的键。

返回
mixed
抛出
InvalidArgumentException

getView() ¶ public

getView(): Cake\View\View

获取此助手绑定的 View 实例。

返回
Cake\View\View

highlight() ¶ public @method

highlight(string $text, array|string $phrase, array $options = []): string

参见 Text::highlight()

参数
string $text
array|string $phrase
array $options 可选
返回
string

implementedEvents() ¶ public

implementedEvents(): array<string, mixed>

事件监听器。

通过定义其中一个回调方法,助手被认为对相关事件感兴趣。

如果您需要添加非传统事件监听器,或者您希望助手监听非标准事件,请重写此方法。

返回
array<string, mixed>

initialize() ¶ public

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

构造函数钩子方法。

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

参数
array<string, mixed> $config

提供给此助手的配置设置。

返回
void

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 可选

要设置的值。

bool $merge 可选

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

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

slug() ¶ public @method

slug(string $string, array|string $options = []): string

参见 Text::slug()

参数
string $string
array|string $options 可选
返回
string

tail() ¶ public @method

tail(string $text, int $length = 100, array $options = []): string

参见 Text::tail()

参数
string $text
int $length 可选
array $options 可选
返回
string

toList() ¶ public @method

toList(array $list, ?string $and = null, string $separator = ', '): string

参见 Text::toList()

参数
array $list
?string $and 可选
string $separator 可选
返回
string

truncate() ¶ public @method

truncate(string $text, int $length = 100, array $options = []): string

参见 Text::truncate()

参数
string $text
int $length 可选
array $options 可选
返回
string

属性详情

$Html ¶ public @property

类型
Cake\View\Helper\HtmlHelper

$_View ¶ protected

此助手所附加的 View 实例

类型
Cake\View\View

$_config ¶ protected

运行时配置

类型
array<string, mixed>

$_configInitialized ¶ protected

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

类型
bool

$_defaultConfig ¶ protected

此助手的默认配置。

类型
array<string, mixed>

$_placeholders ¶ protected

哈希及其内容的数组。在将链接插入文本时使用。

类型
array<string, array>

$helperInstances ¶ protected

加载的助手实例。

类型
array<string,Cake\View\Helper>

$helpers ¶ protected

助手

类型
array
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 手册
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标志和商标
  • 社区
  • 参与进来
  • 问题 (Github)
  • 面包店
  • 推荐资源
  • 训练
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 新闻通讯
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成