qumuinc / ulidtypes
CakePHP 的 UlidType 插件
v0.0.5
2021-10-05 01:43 UTC
Requires
- cakephp/cakephp: ^4.0
- robinvdvleuten/ulid: ^5.0
Requires (Dev)
- phpunit/phpunit: ^5.7.14|^6.0
This package is not auto-updated.
Last update: 2024-10-01 19:50:29 UTC
README
设置
安装
$ composer require qumuinc/ulidtypes
引导
- 在
config/bootstrap.php
中添加插件加载命令
... Plugin::load('qumuinc/UlidTypes', ['bootstrap' => true]); ...
模型
- 将
_initializeSchema()
方法添加到Model\Table
类中,使 id 类型为ulid
... use Cake\Database\Schema\TableSchemaInterface; ... class XXXXXXXXTable extends Table { protected function _initializeSchema(TableSchemaInterface $table): TableSchemaInterface { parent::_initializeSchema($table); $table->setColumnType('id', 'ulid'); // set ulid type for id return $table; } } ...
或者,您可以使用一个特质。
... use PrefixUlidType\PrefixUlidTypeTrait; ... class XXXXXXXXTable extends Table { use PrefixUlidTypeTrait; } ...
如果您想在模型中使用 _initializeSchema
函数,需要调用 _traitInitSchema
函数。
... use Cake\Database\Schema\TableSchemaInterface; use PrefixUlidType\PrefixUlidTypeTrait; ... class XXXXXXXXTable extends Table { use PrefixUlidTypeTrait; protected function _initializeSchema(TableSchemaInterface $table): TableSchemaInterface { parent::_traitInitSchema($table); $table->setColumnType('code', 'char'); // set any type for property return $table; } } ...