Sequence plugin to maintain ordered list of records
Installation
Install this plugin into your CakePHP application using composer:
composer require admad/cakephp-sequence
Then load the plugin by either running:
./bin/cake plugin load ADmad/Sequence
or adding the following line to config/bootstrap.php
:
\Cake\Core\Plugin::load('ADmad/Sequence');
How it works
SequenceBehavior
provided by this plugin maintains a contiguous sequence of
integers in a selected column, for records in a table records (optionally with grouping)
when adding, editing (including moving groups) or deleting records.
Usage
Add the SequenceBehavior
for your table and viola:
$this->addBehavior('ADmad/Sequence.Sequence');
You can customize various options as shown:
$this->addBehavior('ADmad/Sequence.Sequence', [
'order' => 'position', // Field to use to store integer sequence. Default "position".
'scope' => ['group_id'], // Array of field names to use for grouping records. Default [].
'start' => 1, // Initial value for sequence. Default 1.
]);
Acknowledgement
Shout out to @neilcrookes for his wonderful Sequence Behavior for CakePHP 1.3 which was the inspiration for this plugin.