Skip to content

tmazur/cakephp-position-behavior

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CakePHP Position Behavior

Allows quick reordering of your CakePHP models. Supports models with a belongsTo relation, allowing to reorder data within a category.

Requirements

The model must have a field (default: position) which holds the order of the data. If the model has a belongsTo relation, this can be used to order the data within that category.

Installation

Put the PositionBehavior.php file in the /App/Model/Behavior/ folder.

Setup

In your model include the behavior: public $actsAs = array('Position'=>array('categoryField'=>'category_id'));. If no categoryField is used, that part can be ommited public $actsAs = array('Position');, or supply null: public $actsAs = array('Position'=>array('categoryField'=>null));. The default position field can also be changed with the field attribute: public $actsAs = array('Position'=>array('field'=>'order', 'categoryField'=>'category_id'));

Usage

Simply call the model method $model->move($id, 'up');. The data can be moved up/left or down/right. The first entry shall have position no. 1 (appears at the top/leftmost part of the dataset). This behavior overloads the model's onSave method to automatically add new data at the end of the data set.

License

Licensed under MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages