PHPackages                             asper/cakephp-enum-behavior - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. asper/cakephp-enum-behavior

ActiveCakephp-plugin

asper/cakephp-enum-behavior
===========================

Introduces an alternative way to support some ENUM types in CakePHP

1.0(12y ago)101.9k10[1 PRs](https://github.com/asper/CakePHP-Enum-Behavior/pulls)PHP

Since Dec 24Pushed 8y ago3 watchersCompare

[ Source](https://github.com/asper/CakePHP-Enum-Behavior)[ Packagist](https://packagist.org/packages/asper/cakephp-enum-behavior)[ RSS](/packages/asper-cakephp-enum-behavior/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (3)Used By (0)

Enum Behavior
=============

[](#enum-behavior)

CakePHP does not support MySQL's `Enum` fields types. I've commed around 3 solutions to conturn this problem:

- using a second table
- using MySQL's Enum and retrieve EnumValues like in [Baked Enums](http://bakery.cakephp.org/articles/view/baked-enums)

This behavior is using an other approach, it stores the configuration in an array which is fast and flexible. It also creates validation rules and the select lists.

Installation
------------

[](#installation)

Simply download and put it in the `CakePHP-Enum-Behavior` folder and its content in your `app/Plugin` folder.

Load plugin in `app/Config/bootstrap.php` :

```
CakePlugin::load('CakePHP-Enum-Behavior');

```

Using composer:

```
"require" : {
    "asper/cakephp-enum-behavior": "*"
}

```

As a git submodule (execute inside `app/Plugin`):

```
git submodule add https://github.com/asper/CakePHP-Enum-Behavior.git

```

Usage
-----

[](#usage)

Let's assume we have a `posts` table and we want to have a `status` field that could have 3 possible values (`draft`, `published`, `archive`).

Table data :

```
id			int(10)
title		varchar(65)
content		varchar(65)
status		varchar(65)

```

In your `Post` model :

```
public $actsAs = array(
	'CakePHP-Enum-Behavior.Enum' => array(
		'status' => array('draft', 'published', 'archive')
	)
);

```

You can use named keys in associative array with key as data field value

```
public $actsAs = array(
    'CakePHP-Enum-Behavior.Enum' => array(
        'status' => array(23 => 'draft', 'pub' => 'published', 2 => 'archive')
    )
);

```

In your `Posts` controller, in the `beforeRender` callback add :

```
$this->set($this->Post->enumValues());

```

To display the `status` dropdown menu in your forms you just have to use the `FormHelper` as usual :

```
$this->Form->input('Post.status');

```

To display the status in your `view` use :

```
echo $statuses[$post['Post']['status']];

```

If yout want the strings to be translated, add (anywhere in your application \[even if it doesn't seems right\]):

```
__('Draft'); // Humanized value
__('Published');
__('Archive');

```

Credits
-------

[](#credits)

- [kaiyou](https://github.com/kaiyou) : Strict compatibility with CakePHP 2.3.0
- [Andrew Bashtannik](https://github.com/a-bashtannik) : Composer compatibility
- [Tomasz Mazur](https://github.com/tmazur) : Change Plugin name to reflect GitHub project name (allows use of Plugin as git submodule)

License
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2013 Pierre Aboucaya

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 69.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4526d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/317361?v=4)[Bashtannik](/maintainers/bashtannik)[@bashtannik](https://github.com/bashtannik)

![](https://avatars.githubusercontent.com/u/251397?v=4)[Pierre Aboucaya](/maintainers/asper)[@asper](https://github.com/asper)

---

Top Contributors

[![asper](https://avatars.githubusercontent.com/u/251397?v=4)](https://github.com/asper "asper (16 commits)")[![tmazur](https://avatars.githubusercontent.com/u/202591?v=4)](https://github.com/tmazur "tmazur (3 commits)")[![kaiyou](https://avatars.githubusercontent.com/u/847861?v=4)](https://github.com/kaiyou "kaiyou (2 commits)")[![13i](https://avatars.githubusercontent.com/u/1174353?v=4)](https://github.com/13i "13i (1 commits)")[![a-bashtannik](https://avatars.githubusercontent.com/u/2712350?v=4)](https://github.com/a-bashtannik "a-bashtannik (1 commits)")

---

Tags

enumcakephpBehavior

### Embed Badge

![Health badge](/badges/asper-cakephp-enum-behavior/health.svg)

```
[![Health](https://phpackages.com/badges/asper-cakephp-enum-behavior/health.svg)](https://phpackages.com/packages/asper-cakephp-enum-behavior)
```

###  Alternatives

[josegonzalez/cakephp-upload

CakePHP plugin to handle file uploading sans ridiculous automagic

5451.3M9](/packages/josegonzalez-cakephp-upload)[cakedc/enum

Enumeration list Plugin for CakePHP 5

30222.5k2](/packages/cakedc-enum)[lorenzo/linkable

CakePHP Linkable Behavior

2753.3k](/packages/lorenzo-linkable)[itosho/easy-query

CakePHP behavior plugin for easily generating some complicated queries like (bulk) insert/upsert etc.

2623.2k](/packages/itosho-easy-query)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
