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
      • Driver
      • Exception
      • Expression
      • Log
      • Query
      • Retry
      • Schema
      • Statement
      • Type
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

接口 TableSchemaInterface

数据库 TableSchema 对象使用的接口。

命名空间: Cake\Database\Schema

常量

  • 数组
    GEOSPATIAL_TYPES ¶
    [self::TYPE_GEOMETRY, self::TYPE_POINT, self::TYPE_LINESTRING, self::TYPE_POLYGON]

    地理空间列类型

  • 字符串
    TYPE_BIGINTEGER ¶
    'biginteger'

    大整数列类型

  • 字符串
    TYPE_BINARY ¶
    'binary'

    二进制列类型

  • 字符串
    TYPE_BINARY_UUID ¶
    'binaryuuid'

    二进制 UUID 列类型

  • 字符串
    TYPE_BOOLEAN ¶
    'boolean'

    布尔列类型

  • 字符串
    TYPE_CHAR ¶
    'char'

    字符列类型

  • 字符串
    TYPE_DATE ¶
    'date'

    日期列类型

  • 字符串
    TYPE_DATETIME ¶
    'datetime'

    日期时间列类型

  • 字符串
    TYPE_DATETIME_FRACTIONAL ¶
    'datetimefractional'

    带小数秒的日期时间列类型

  • 字符串
    TYPE_DECIMAL ¶
    'decimal'

    小数列类型

  • 字符串
    TYPE_FLOAT ¶
    'float'

    浮点列类型

  • 字符串
    TYPE_GEOMETRY ¶
    'geometry'

    几何列类型

  • 字符串
    TYPE_INTEGER ¶
    'integer'

    整数列类型

  • 字符串
    TYPE_JSON ¶
    'json'

    JSON 列类型

  • 字符串
    TYPE_LINESTRING ¶
    'linestring'

    线串列类型

  • 字符串
    TYPE_POINT ¶
    'point'

    点列类型

  • 字符串
    TYPE_POLYGON ¶
    'polygon'

    多边形列类型

  • 字符串
    TYPE_SMALLINTEGER ¶
    'smallinteger'

    小整数列类型

  • 字符串
    TYPE_STRING ¶
    'string'

    字符串列类型

  • 字符串
    TYPE_TEXT ¶
    'text'

    文本列类型

  • 字符串
    TYPE_TIME ¶
    'time'

    时间列类型

  • 字符串
    TYPE_TIMESTAMP ¶
    'timestamp'

    时间戳列类型

  • 字符串
    TYPE_TIMESTAMP_FRACTIONAL ¶
    'timestampfractional'

    带小数秒的时间戳列类型

  • 字符串
    TYPE_TIMESTAMP_TIMEZONE ¶
    'timestamptimezone'

    带时区的时间戳列类型

  • 字符串
    TYPE_TINYINTEGER ¶
    'tinyinteger'

    极小整数列类型

  • 字符串
    TYPE_UUID ¶
    'uuid'

    UUID 列类型

方法摘要

  • addColumn() public

    向表中添加一列。

  • addConstraint() public

    添加约束。

  • addIndex() public

    添加索引。

  • baseColumnType() public

    返回提供的列的基本类型名称。这表示更复杂的类所基于的数据库类型。

  • columns() public

    获取表中的列名。

  • constraints() public

    获取表中所有约束的名称。

  • defaultValues() public

    获取列及其默认值的哈希值。

  • dropConstraint() public

    删除约束。

  • getColumn() public

    获取表中的列数据。

  • getColumnType() public

    返回列类型,如果列不存在则返回 null。

  • getConstraint() public

    根据名称读取有关约束的信息。

  • getIndex() public

    根据名称读取有关索引的信息。

  • getOptions() public

    获取表的选项。

  • getPrimaryKey() public

    获取用作主键的列。

  • hasAutoincrement() public

    检查表是否定义了自动递增列。

  • hasColumn() public

    如果模式中存在列,则返回 true。

  • indexes() public

    获取表中所有索引的名称。

  • isNullable() public

    检查字段是否可为空

  • isTemporary() public

    获取表在数据库中是否为临时表。

  • name() public

    获取表名。

  • removeColumn() public

    从表模式中删除一列。

  • setColumnType() public

    设置列类型。

  • setOptions() public

    设置表的选项。

  • setTemporary() public

    设置表在数据库中是否为临时表。

  • typeMap() public

    返回一个数组,其中键是模式中的列名,值是它们具有的数据库类型。

方法详情

addColumn() ¶ public

addColumn(string $name, array<string, mixed>|string $attrs): $this

向表中添加一列。

属性

列可以具有多个属性

  • type 列的类型。这应该是 CakePHP 的抽象类型之一。
  • length 列的长度。
  • precision 用于存储浮点数和十进制类型的小数位数。
  • default 列的默认值。
  • null 列是否可以为空。
  • fixed 列是否为固定长度列。 这只对字符串列存在/有效。
  • unsigned 列是否为无符号列。 这只对整数、十进制、浮点数列存在/有效。

除了以上键之外,以下键在某些数据库方言中实现,但并非所有方言都实现。

  • comment 列的注释。
参数
string $name

列的名称

array<string, mixed>|string $attrs

列的属性或类型名称。

返回值
$this

addConstraint() ¶ public

addConstraint(string $name, array<string, mixed>|string $attrs): $this

添加约束。

用于向表添加约束。 例如主键、唯一键和外键。

属性

  • type 要添加的约束类型。
  • columns 索引中的列。
  • references 外键引用的表、列。
  • update 更新时的行为。 选项是 'restrict'、'setNull'、'cascade'、'noAction'。
  • delete 删除时的行为。 选项是 'restrict'、'setNull'、'cascade'、'noAction'。

'update' 和 'delete' 的默认值为 'cascade'。

参数
string $name

约束的名称。

array<string, mixed>|string $attrs

约束的属性。 如果是字符串,它将用作 type。

返回值
$this
抛出
Cake\Database\Exception\DatabaseException

addIndex() ¶ public

addIndex(string $name, array<string, mixed>|string $attrs): $this

添加索引。

用于添加索引,以及支持它们的平台上的全文索引。

属性

  • type 要添加的索引类型。
  • columns 索引中的列。
参数
string $name

索引的名称。

array<string, mixed>|string $attrs

索引的属性。 如果是字符串,它将用作 type。

返回值
$this
抛出
Cake\Database\Exception\DatabaseException

baseColumnType() ¶ public

baseColumnType(string $column): string|null

返回提供的列的基本类型名称。这表示更复杂的类所基于的数据库类型。

参数
string $column

要从中获取基本类型的列名称

返回值
string|null

columns() ¶ public

columns(): list<string>

获取表中的列名。

返回值
list<string>

constraints() ¶ public

constraints(): list<string>

获取表中所有约束的名称。

返回值
list<string>

defaultValues() ¶ public

defaultValues(): array<string, mixed>

获取列及其默认值的哈希值。

返回值
array<string, mixed>

dropConstraint() ¶ public

dropConstraint(string $name): $this

删除约束。

参数
string $name

要删除的约束的名称

返回值
$this

getColumn() ¶ public

getColumn(string $name): array<string, mixed>|null

获取表中的列数据。

参数
string $name

列名称。

返回值
array<string, mixed>|null

getColumnType() ¶ public

getColumnType(string $name): string|null

返回列类型,如果列不存在则返回 null。

参数
string $name

要获取类型的列。

返回值
string|null

getConstraint() ¶ public

getConstraint(string $name): array<string, mixed>|null

根据名称读取有关约束的信息。

参数
string $name

约束的名称。

返回值
array<string, mixed>|null

getIndex() ¶ public

getIndex(string $name): array<string, mixed>|null

根据名称读取有关索引的信息。

参数
string $name

索引的名称。

返回值
array<string, mixed>|null

getOptions() ¶ public

getOptions(): array<string, mixed>

获取表的选项。

表选项允许您设置平台特定的表级选项。 例如 MySQL 中的引擎类型。

返回值
array<string, mixed>

getPrimaryKey() ¶ public

getPrimaryKey(): list<string>

获取用作主键的列。

返回值
list<string>

hasAutoincrement() ¶ public

hasAutoincrement(): bool

检查表是否定义了自动递增列。

返回值
bool

hasColumn() ¶ public

hasColumn(string $name): bool

如果模式中存在列,则返回 true。

参数
string $name

列名称。

返回值
bool

indexes() ¶ public

indexes(): list<string>

获取表中所有索引的名称。

返回值
list<string>

isNullable() ¶ public

isNullable(string $name): bool

检查字段是否可为空

缺少的列是可空的。

参数
string $name

要获取类型的列。

返回值
bool

isTemporary() ¶ public

isTemporary(): bool

获取表在数据库中是否为临时表。

返回值
bool

name() ¶ public

name(): string

获取表名。

返回值
字符串

removeColumn() ¶ public

removeColumn(string $name): $this

从表模式中删除一列。

如果表中未定义列,则不会引发错误。

参数
string $name

列的名称

返回值
$this

setColumnType() ¶ public

setColumnType(string $name, string $type): $this

设置列类型。

参数
string $name

要设置类型的列。

string $type

要设置为列的类型。

返回值
$this

setOptions() ¶ public

setOptions(array<string, mixed> $options): $this

设置表的选项。

表选项允许您设置平台特定的表级选项。 例如 MySQL 中的引擎类型。

参数
array<string, mixed> $options

要设置的选项,或 null 以读取选项。

返回值
$this

setTemporary() ¶ public

setTemporary(bool $temporary): $this

设置表在数据库中是否为临时表。

参数
bool $temporary

表是否为临时表。

返回值
$this

typeMap() ¶ public

typeMap(): array<string, string>

返回一个数组,其中键是模式中的列名,值是它们具有的数据库类型。

返回值
array<string, string>
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 徽标和商标
  • 社区
  • 参与进来
  • 问题 (Github)
  • 面包店
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 新闻稿
  • 领英
  • YouTube
  • 脸书
  • 推特
  • Mastodon
  • 帮助与支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成