k1low / stateful-enum
为 CakePHP 3 设计的简单状态枚举插件
v0.1.0
2016-04-06 06:03 UTC
Requires
- php: >=5.4.16
- cakephp/cakephp: ~3.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-06 09:29:29 UTC
README
安装
您可以使用composer将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方式是
composer require k1low/stateful-enum
用法
class BugsTable extends Table { const STATUS_UNASSIGNED = 'unassigned'; const STATUS_ASSIGNED = 'assigned'; const STATUS_RESOLVED = 'resolved'; const STATUS_CLOSED = 'closed'; public $transitions = [ 'status' => [ 'assign' => [ 'from' => self::STATUS_UNASSIGNED, 'to' => self::STATUS_ASSIGNED ], 'resolve' => [ [self::STATUS_ASSIGNED, self::STATUS_UNASSIGNED], // from self::STATUS_RESOLVED // to ], 'close' => [ [self::STATUS_ASSIGNED, self::STATUS_UNASSIGNED, self::STATUS_RESOLVED], self::STATUS_CLOSED ], ] ]; public function initialize(array $config) { $this->primaryKey('id'); $this->addBehavior('StatefulEnum.StatefulEnum'); } }
因此,此插件会自动设置构建状态规则。