CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 徽标和商标
  • 商业解决方案
  • 纪念品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与进来
    • 问题 (Github)
    • Bakery
    • 特色资源
    • 培训
    • 聚会
    • 我的 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

类 ValidationSet

ValidationSet 对象。持有字段的所有验证规则,并公开方法以动态添加或删除验证规则

命名空间: Cake\Validation

属性摘要

  • $_allowEmpty protected
    callable|string|bool

    表示字段是否允许为空

  • $_rules protected
    arrayCake\Validation\ValidationRule>

    保存 ValidationRule 对象

  • $_validatePresent protected
    callable|string|bool

    表示字段名键是否必须存在于数据数组中

方法摘要

  • add() public

    使用 $name 设置 ValidationRule $rule

  • allowEmpty() public

    设置字段值是否允许为空。

  • count() public

    返回此集中规则的数量

  • getIterator() public

    返回每个要应用的规则的迭代器

  • isEmptyAllowed() public

    返回字段是否可以为空。

  • isPresenceRequired() public

    返回字段是否可以省略。

  • offsetExists() public

    返回规则集中是否存在索引

  • offsetGet() public

    按其索引返回规则对象

  • offsetSet() public

    设置或替换验证规则

  • offsetUnset() public

    取消设置验证规则

  • remove() public

    从集中删除验证规则

  • requirePresence() public

    设置字段是否需要存在于数据数组中。

  • rule() public

    如果存在,获取给定名称的规则

  • rules() public

    返回此验证集的所有规则

方法详情

add() ¶ public

add(string $name, Cake\Validation\ValidationRule|array $rule): $this

使用 $name 设置 ValidationRule $rule

示例

     $set
         ->add('notBlank', ['rule' => 'notBlank'])
         ->add('inRange', ['rule' => ['between', 4, 10])
参数
string $name

应该设置规则的名称

Cake\Validation\ValidationRule|array $rule

要设置的验证规则

返回值
$this

allowEmpty() ¶ public

allowEmpty(callable|string|bool $allowEmpty): $this

设置字段值是否允许为空。

参数
callable|string|bool $allowEmpty

有效值为 true、false、'create'、'update' 或可调用对象。

返回值
$this

count() ¶ public

count(): int

返回此集中规则的数量

返回值
int

getIterator() ¶ public

getIterator(): Traversable<string,Cake\Validation\ValidationRule>

返回每个要应用的规则的迭代器

返回值
Traversable<string,Cake\Validation\ValidationRule>

isEmptyAllowed() ¶ public

isEmptyAllowed(): callable|string|bool

返回字段是否可以为空。

返回值
callable|string|bool

isPresenceRequired() ¶ public

isPresenceRequired(): callable|string|bool

返回字段是否可以省略。

返回值
callable|string|bool

offsetExists() ¶ public

offsetExists(string $index): bool

返回规则集中是否存在索引

参数
string $index

规则的名称

返回值
bool

offsetGet() ¶ public

offsetGet(string $index): Cake\Validation\ValidationRule

按其索引返回规则对象

参数
string $index

规则的名称

返回值
Cake\Validation\ValidationRule

offsetSet() ¶ public

offsetSet(string $offset, Cake\Validation\ValidationRule|array $value): void

设置或替换验证规则

参数
string $offset

规则的名称

Cake\Validation\ValidationRule|array $value

要添加到 $index 的规则

返回值
void

offsetUnset() ¶ public

offsetUnset(string $index): void

取消设置验证规则

参数
string $index

规则的名称

返回值
void

remove() ¶ public

remove(string $name): $this

从集中删除验证规则

示例

     $set
         ->remove('notBlank')
         ->remove('inRange')
参数
string $name

应该取消设置规则的名称

返回值
$this

requirePresence() ¶ public

requirePresence(callable|string|bool $validatePresent): $this

设置字段是否需要存在于数据数组中。

参数
callable|string|bool $validatePresent

有效值为 true、false、'create'、'update' 或可调用对象。

返回值
$this

rule() ¶ public

rule(string $name): Cake\Validation\ValidationRule|null

如果存在,获取给定名称的规则

参数
string $name

设置规则的名称。

返回值
Cake\Validation\ValidationRule|null

rules() ¶ public

rules(): arrayCake\Validation\ValidationRule>

返回此验证集的所有规则

返回值
arrayCake\Validation\ValidationRule>

属性详情

$_allowEmpty ¶ protected

表示字段是否允许为空

类型
callable|string|bool

$_rules ¶ protected

保存 ValidationRule 对象

类型
arrayCake\Validation\ValidationRule>

$_validatePresent ¶ protected

表示字段名键是否必须存在于数据数组中

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

使用 CakePHP API 文档 生成