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

类 RadioWidget

用于生成一组单选按钮的输入小部件类。

此类通常由Cake\View\Helper\FormHelper在内部使用,但可以用来生成独立的单选按钮。

命名空间: Cake\View\Widget

属性概要

  • $_idPrefix protected
    string|null

    id 属性的前缀。

  • $_idSuffixes protected
    list<string>

    当前渲染中使用的一系列 id 后缀。

  • $_label protected
    Cake\View\Widget\LabelWidget

    标签实例。

  • $_templates protected
    Cake\View\StringTemplate

    StringTemplate 实例。

  • $defaults protected
    array<string, mixed>

    数据默认值。

方法概要

  • __construct() public

    构造函数

  • _clearIds() protected

    清除存储的 ID 后缀。

  • _domId() protected

    生成适合用在 ID 属性中的 ID。

  • _id() protected

    为元素生成 ID 属性。

  • _idSuffix() protected

    生成 ID 后缀。

  • _isDisabled() protected

    禁用属性检测。

  • _renderInput() protected

    渲染单个单选按钮的输入和标签。

  • _renderLabel() protected

    为给定的单选按钮渲染标签元素。

  • mergeDefaults() protected

    将默认值与提供的 data 合并。

  • render() public

    渲染一组单选按钮。

  • secureFields() public

    返回此小部件需要安全保护的字段列表。

  • setMaxLength() protected

    如果适用,设置 "maxlength" 属性的值。

  • setRequired() protected

    如果适用,设置 "required" 属性的值。

  • setStep() protected

    如果适用,设置 "step" 属性的值。

方法详情

__construct() ¶ public

__construct(Cake\View\StringTemplate $templates, Cake\View\Widget\LabelWidget $label)

构造函数

此类使用以下模板

  • radio 用于生成单选按钮的输入。可以使用以下变量 name、value、attrs。
  • radioWrapper 用于生成单选按钮 + 输入元素的容器元素。可以使用 input 和 label 变量。
参数
Cake\View\StringTemplate $templates

模板列表。

Cake\View\Widget\LabelWidget $label

标签小部件实例。

_clearIds() ¶ protected

_clearIds(): void

清除存储的 ID 后缀。

返回
void

_domId() ¶ protected

_domId(string $value): string

生成适合用在 ID 属性中的 ID。

参数
string $value

要转换为 ID 的值。

返回
string

_id() ¶ protected

_id(string $name, string $val): string

为元素生成 ID 属性。

确保给定字段集的 id 唯一。

参数
string $name

ID 属性名称。

string $val

ID 属性值。

返回
string

_idSuffix() ¶ protected

_idSuffix(string $val): string

生成 ID 后缀。

确保给定字段集的 id 唯一。

参数
string $val

ID 属性值。

返回
string

_isDisabled() ¶ protected

_isDisabled(array<string, mixed> $radio, array|string|true|null $disabled): bool

禁用属性检测。

参数
array<string, mixed> $radio

单选按钮信息。

array|string|true|null $disabled

禁用值。

返回
bool

_renderInput() ¶ protected

_renderInput(string|int $val, array<string, mixed>|string|int $text, array<string, mixed> $data, Cake\View\Form\ContextInterface $context): string

渲染单个单选按钮的输入和标签。

参数
string|int $val

单选按钮输入的值。

array<string, mixed>|string|int $text

标签文本或复杂的单选按钮类型。

array<string, mixed> $data

输入生成的其他选项。

Cake\View\Form\ContextInterface $context

表单上下文

返回
string

_renderLabel() ¶ protected

_renderLabel(array<string, mixed> $radio, array<string, mixed>|string|bool|null $label, string $input, Cake\View\Form\ContextInterface $context, bool $escape): string|false

为给定的单选按钮渲染标签元素。

将来这可能会被重构为一个单独的小部件,因为其他输入类型(多选框)也将需要生成标签。

参数
array<string, mixed> $radio

输入属性。

array<string, mixed>|string|bool|null $label

标签的属性。

string $input

输入小部件。

Cake\View\Form\ContextInterface $context

表单上下文。

bool $escape

是否对标签进行 HTML 转义。

返回
string|false

mergeDefaults() ¶ protected

mergeDefaults(array<string, mixed> $data, Cake\View\Form\ContextInterface $context): array<string, mixed>

将默认值与提供的 data 合并。

参数
array<string, mixed> $data

数据数组

Cake\View\Form\ContextInterface $context

上下文实例。

返回
array<string, mixed>

render() ¶ public

render(array<string, mixed> $data, Cake\View\Form\ContextInterface $context): string

渲染一组单选按钮。

Data 支持以下键

  • name - 设置输入名称。
  • options - 选项数组。有关更多信息,请参见下文。
  • disabled - 为 true 或要禁用的输入数组。当为 true 时,选择元素将被禁用。
  • val - 要标记为选中的选项的字符串。
  • label - 为 false 则禁用标签生成,或为所有标签的属性数组。
  • required - 设置为 true 则在所有生成的单选按钮上添加 required 属性。
  • idPrefix 生成的 ID 属性的前缀。
参数
array<string, mixed> $data

用于构建单选按钮的数据。

Cake\View\Form\ContextInterface $context

当前表单上下文。

返回
string

secureFields() ¶ public

secureFields(array<string, mixed> $data): list<string>

返回此小部件需要安全保护的字段列表。

参数
array<string, mixed> $data
返回
list<string>

setMaxLength() ¶ protected

setMaxLength(array<string, mixed> $data, Cake\View\Form\ContextInterface $context, string $fieldName): array<string, mixed>

如果适用,设置 "maxlength" 属性的值。

参数
array<string, mixed> $data

数据数组

Cake\View\Form\ContextInterface $context

上下文实例。

string $fieldName

字段名称。

返回
array<string, mixed>

setRequired() ¶ protected

setRequired(array<string, mixed> $data, Cake\View\Form\ContextInterface $context, string $fieldName): array<string, mixed>

如果适用,设置 "required" 属性的值。

参数
array<string, mixed> $data

数据数组

Cake\View\Form\ContextInterface $context

上下文实例。

string $fieldName

字段名称。

返回
array<string, mixed>

setStep() ¶ 受保护

setStep(array<string, mixed> $data, Cake\View\Form\ContextInterface $context, string $fieldName): array<string, mixed>

如果适用,设置 "step" 属性的值。

参数
array<string, mixed> $data

数据数组

Cake\View\Form\ContextInterface $context

上下文实例。

string $fieldName

字段名称。

返回
array<string, mixed>

属性详情

$_idPrefix ¶ 受保护

id 属性的前缀。

类型
string|null

$_idSuffixes ¶ 受保护

当前渲染中使用的一系列 id 后缀。

类型
list<string>

$_label ¶ 受保护

标签实例。

类型
Cake\View\Widget\LabelWidget

$_templates ¶ 受保护

StringTemplate 实例。

类型
Cake\View\StringTemplate

$defaults ¶ 受保护

数据默认值。

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

使用 CakePHP API 文档 生成