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

类 NumberHelper

数字助手库。

使数字更易读的方法。

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

属性摘要

  • $_View protected
    Cake\View\View

    此助手附加到的视图实例

  • $_config protected
    array<string, mixed>

    运行时配置

  • $_configInitialized protected
    bool

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

  • $_defaultConfig protected
    array<string, mixed>

    此助手的默认配置。

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

    已加载的助手实例。

  • $helpers protected
    array

    此助手使用的助手列表

方法摘要

  • __call() public

    调用 Cake\I18n\Number 工具类中的方法

  • __construct() public

    默认构造函数

  • __debugInfo() public

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

  • __get() public

    延迟加载助手。

  • _configDelete() protected

    删除单个配置键。

  • _configRead() protected

    读取配置键。

  • _configWrite() protected

    写入配置键。

  • _confirm() protected

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

  • addClass() public

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

  • configShallow() public

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

  • currency() public

    将数字格式化为货币格式。

  • format() public

    将数字格式化为正确的区域设置格式

  • formatDelta() public

    将数字格式化为正确的区域设置格式以显示增量(值的有符号差异)。

  • getConfig() public

    返回配置。

  • getConfigOrFail() public

    返回此特定键的配置。

  • getView() public

    获取此助手绑定的视图实例。

  • implementedEvents() public

    事件监听器。

  • initialize() public

    构造函数钩子方法。

  • ordinal() public @method

    参见 Number::ordinal()

  • precision() public @method

    参见 Number::precision()

  • setConfig() public

    设置配置。

  • toPercentage() public @method

    参见 Number::toPercentage()

  • toReadableSize() public @method

    参见 Number::toReadableSize()

方法详情

__call() ¶ public

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

调用 Cake\I18n\Number 工具类中的方法

参数
string $method

要调用的方法

array $params

方法的参数数组。

返回
mixed

__construct() ¶ public

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

默认构造函数

参数
Cake\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

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>

configShallow() ¶ public

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

将提供的配置与现有配置合并。与 config() 不同,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

currency() ¶ public

currency(string|float $number, string|null $currency = null, array<string, mixed> $options = []): string

将数字格式化为货币格式。

选项

  • locale - 用于格式化数字的区域设置名称,例如 fr_FR
  • fractionSymbol - 用于分数的货币符号。
  • fractionPosition - 分数符号应放置的位置,有效选项为 'before' 和 'after'。
  • before - 在渲染的数字之前显示的文本
  • after - 在渲染的数字之后显示的文本
  • zero - 用于零值的文本,可以是字符串或数字。例如 0,'免费!'
  • places - 要使用的十进制位数。例如 2
  • precision - 要使用的最大十进制位数,例如 2
  • roundingMode - 要使用的舍入模式。例如 NumberFormatter::ROUND_HALF_UP。如果未设置,将使用区域设置默认值
  • pattern - 用于格式化数字的 ICU 数字模式。例如 #,##0.00
  • useIntlCode - 是否将货币符号替换为国际货币代码。
  • escape - 是否在生成的字符串中转义 html
参数
string|float $number

要格式化的值。

string|null $currency 可选

国际货币名称,例如 'USD'、'EUR'、'JPY'、'CAD'

array<string, mixed> $options 可选

选项列表。

返回
string

format() ¶ 公共

format(string|float|int $number, array<string, mixed> $options = []): string

将数字格式化为正确的区域设置格式

选项

  • places - 要使用的最小小数位数,例如 0
  • precision - 要使用的最大十进制位数,例如 2
  • locale - 用于格式化数字的区域设置名称,例如 fr_FR
  • before - 要放在整数之前的字符串,例如 '['
  • after - 要放在小数之后的字符串,例如 ']'
  • escape - 是否在生成的字符串中转义 html
参数
string|float|int $number

一个浮点数。

array<string, mixed> $options 可选

包含选项的数组。

返回
string
链接
https://book.cakephp.com.cn/5/en/views/helpers/number.html#formatting-numbers

formatDelta() ¶ 公共

formatDelta(string|float $value, array<string, mixed> $options = []): string

将数字格式化为正确的区域设置格式以显示增量(值的有符号差异)。

选项

  • places - 要使用的最小小数位数,例如 0
  • precision - 要使用的最大十进制位数,例如 2
  • locale - 用于格式化数字的区域设置名称,例如 fr_FR
  • before - 要放在整数之前的字符串,例如 '['
  • after - 要放在小数之后的字符串,例如 ']'
  • escape - 设置为 false 以防止转义
参数
string|float $value

一个浮点数

array<string, mixed> $options 可选

选项列表。

返回
string

getConfig() ¶ 公共

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() ¶ 公共

getConfigOrFail(string $key): mixed

返回此特定键的配置。

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

参数
string $key

要获取的键。

返回
mixed
抛出
InvalidArgumentException

getView() ¶ 公共

getView(): Cake\View\View

获取此助手绑定的视图实例。

返回
Cake\View\View

implementedEvents() ¶ 公共

implementedEvents(): array<string, mixed>

事件监听器。

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

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

返回
array<string, mixed>

initialize() ¶ 公共

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

构造函数钩子方法。

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

参数
array<string, mixed> $config

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

返回
void

ordinal() ¶ 公共 @method

ordinal(float|int $value, array $options = []): string

参见 Number::ordinal()

参数
float|int $value
array $options 可选
返回
string

precision() ¶ 公共 @method

precision(string|float|int $number, int $precision = 3, array $options = []): string

参见 Number::precision()

参数
string|float|int $number
int $precision 可选
array $options 可选
返回
string

setConfig() ¶ 公共

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
尝试设置无效的键时。

toPercentage() ¶ 公共 @method

toPercentage(string|float|int $value, int $precision = 3, array $options = []): string

参见 Number::toPercentage()

参数
string|float|int $value
int $precision 可选
array $options 可选
返回
string

toReadableSize() ¶ 公共 @method

toReadableSize(string|float|int $size): string

参见 Number::toReadableSize()

参数
string|float|int $size
返回
string

属性详细信息

$_View ¶ 受保护

此助手附加到的视图实例

类型
Cake\View\View

$_config ¶ 受保护

运行时配置

类型
array<string, mixed>

$_configInitialized ¶ 受保护

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

类型
bool

$_defaultConfig ¶ 受保护

此助手的默认配置。

类型
array<string, mixed>

$helperInstances ¶ 受保护

已加载的助手实例。

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

$helpers ¶ 受保护

此助手使用的助手列表

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

使用 CakePHP API 文档 生成