jeanvaljean / active-behavior
Active plugin for CakePHP
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=5.6.0
- cakephp/orm: ~3.0
Requires (Dev)
- cakephp/cakephp: ^3.6
- phpunit/phpunit: ^5.7.14|^6.0
This package is auto-updated.
Last update: 2024-10-29 05:28:52 UTC
README
A plugin to manage an active column
This plugin is for CakePHP 3.6+.
Setup
composer require jeanvaljean/active-behavior
Usage
Make sure the table that you want for using the active plugin has a column to store the active state of an entity. According to the pluging default configuration this column has to be named "active" and has to be:
['type' => 'integer', 'default' => 0, 'limit' => 1, 'null' => false]
Note : If you want to use an other column to store the active state of an entity, you can do it, you just have to mention it into pluing configuration using "active_field".
Add the Active behavior in initialize()
method of your table:
$this->addBehavior('Active.Active');
Now the active behavior is available on this table class.
Configuration
The behavior configuration allow you to mention :
- active_field : the table's field you want for storing the active state of an entity
- group : the table's field you want to use for grouping the active behavior on specific entities
- keep_active : to make sure that always one entity is active
- multiple : to authorize several entities to be active
The default plugin configuration is as below :
$this->addBehavior('Active.Active', [ 'active_field' => 'active', // the table's field you want for storing the active state of an entity 'group' => '', // the table's field you want to use for grouping the active behavior on specific entities 'keep_active' => true, // to make sure that always one entity is active 'multiple' => false // to authorize several entities to be active ]);