CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 纪念品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与其中
    • 问题 (Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 新闻通讯
    • 领英
    • YouTube
    • 脸书
    • 推特
    • 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

类 ArrayContext

为 FormHelper 提供基本的基于数组的上下文提供者。

此适配器在测试或表单由简单的数组数据结构支持时很有用。

重要键

  • data 存储为字段提供的当前值。
  • defaults 字段的默认值。当没有设置数据时,将使用这些值。数据应按照您使用点分隔路径访问字段的方式进行嵌套。
  • required 字段、关系和布尔标志的嵌套数组,用于指示字段是否必填。该值也可以是字符串,用作必填错误消息。
  • schema 一组模拟 {@link \Cake\Database\Schema\TableSchema} 使用的列结构的数据。此数组允许您控制字段的推断类型,并允许自动生成诸如 maxlength、step 和其他 HTML 属性之类的属性。如果您希望主键/ID 检测正常工作。确保您提供了一个包含 primary 的 _constraints 数组。请参阅下面的示例。
  • errors 验证错误的数组。错误应按照您使用点分隔路径访问字段的方式进行嵌套。

示例

 $article = [
   'data' => [
     'id' => '1',
     'title' => 'First post!',
   ],
   'schema' => [
     'id' => ['type' => 'integer'],
     'title' => ['type' => 'string', 'length' => 255],
     '_constraints' => [
       'primary' => ['type' => 'primary', 'columns' => ['id']]
     ]
   ],
   'defaults' => [
     'title' => 'Default title',
   ],
   'required' => [
     'id' => true, // will use default required message
     'title' => 'Please enter a title',
     'body' => false,
   ],
 ];
命名空间: Cake\View\Form

常量

  • list<string>
    VALID_ATTRIBUTES ¶
    ['length', 'precision', 'comment', 'null', 'default']

属性摘要

  • $_context protected
    array<string, mixed>

    此对象的上下文数据。

方法摘要

  • __construct() public

    构造函数。

  • attributes() public

    获取字段名称的其他属性的关联数组。

  • error() public

    获取给定字段的错误。

  • fieldNames() public

    获取此上下文中的顶级对象的字段名称。

  • getMaxLength() public

    从验证中获取字段长度。

  • getPrimaryKey() public

    获取用作此上下文主键的字段。

  • getRequiredMessage() public

    获取字段的默认“必填”错误消息。

  • hasError() public

    检查字段是否附加了错误。

  • isCreate() public

    返回此表单是否用于创建操作。

  • isPrimaryKey() public

    如果传递的字段名称是此上下文的primaryKey的一部分,则返回true。

  • isRequired() public

    检查给定字段是否“必填”。

  • stripNesting() protected

    剥离任何数字嵌套。

  • type() public

    获取给定字段名称的抽象字段类型。

  • val() public

    获取给定字段的当前值。

方法详情

__construct() ¶ public

__construct(array $context)

构造函数。

参数
array $context

上下文信息。

attributes() ¶ public

attributes(string $field): array

获取字段名称的其他属性的关联数组。

参数
string $field

点分隔路径,用于获取其他数据。

返回
array

error() ¶ public

error(string $field): array

获取给定字段的错误。

参数
string $field

点分隔路径,用于检查错误。

返回
array

fieldNames() ¶ public

fieldNames(): list<string>

获取此上下文中的顶级对象的字段名称。

返回
list<string>

getMaxLength() ¶ public

getMaxLength(string $field): int|null

从验证中获取字段长度。

在此上下文类中,这由“长度”数组简单定义。

参数
string $field

点分隔路径,用于检查必填项。

返回
int|null

getPrimaryKey() ¶ public

getPrimaryKey(): list<string>

获取用作此上下文主键的字段。

返回
list<string>

getRequiredMessage() ¶ public

getRequiredMessage(string $field): string|null

获取字段的默认“必填”错误消息。

参数
string $field
返回
string|null

hasError() ¶ public

hasError(string $field): bool

检查字段是否附加了错误。

参数
string $field

点分隔路径,用于检查错误。

返回
bool

isCreate() ¶ public

isCreate(): bool

返回此表单是否用于创建操作。

为了使此方法返回 true,主键约束必须在“schema”数据中定义,并且“defaults”数据必须包含该键中所有字段的值。

返回
bool

isPrimaryKey() ¶ public

isPrimaryKey(string $field): bool

如果传递的字段名称是此上下文的primaryKey的一部分,则返回true。

参数
string $field
返回
bool

isRequired() ¶ public

isRequired(string $field): bool|null

检查给定字段是否“必填”。

在此上下文类中,这由“required”数组简单定义。

参数
string $field

点分隔路径,用于检查必填项。

返回
bool|null

stripNesting() ¶ protected

stripNesting(string $field): string

剥离任何数字嵌套。

例如 users.0.age 将输出为 users.age

参数
string $field

点分隔路径

返回
string

type() ¶ public

type(string $field): string|null

获取给定字段名称的抽象字段类型。

参数
string $field

点分隔路径,用于获取架构类型。

返回
string|null
另请参阅
\Cake\Database\TypeFactory

val() ¶ public

val(string $field, array<string, mixed> $options = []): mixed

获取给定字段的当前值。

此方法将合并当前数据和“defaults”数组。

参数
string $field

点分隔路径,指向需要值的字段。

array<string, mixed> $options optional

选项

返回
mixed

属性详情

$_context ¶ protected

此对象的上下文数据。

类型
array<string, mixed>
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与其中
  • 问题 (Github)
  • 烘焙坊
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 新闻通讯
  • 领英
  • YouTube
  • 脸书
  • 推特
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成