jeanvaljean/active-behavior

Active plugin for CakePHP

3.1.0 2018-10-02 12:48 UTC

This package is auto-updated.

Last update: 2024-10-29 05:28:52 UTC


README

Build Status Latest Stable Version Minimum PHP Version License Total Downloads

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
]);