Automates conversion of data from one form to another in beforeSave/afterFind in a CakePHP App.
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
models/behaviors
tests
README.mdown

README.mdown

Convertable Behaviour

Ever had data in one format, yet wanted to save it in the db in another? This behaviour will deal with that for you!

Usage

In your model: var $actsAs = array('Convertable.Convertable' => array( 'field' => array( 'beforeSave' => 'convertToDbFormatFunction', 'afterFind' => 'convertFromDbFormatFunction' ) ));

e.g. I like storing IP addresses as integers, but am normally given them as 123.123.123.123 format. var $actsAs = array('Convertable.Convertable' => array( 'field' => array( 'beforeSave' => 'ipToLong', 'afterFind' => 'longToIp' ) ));

The call back functions can be defined on your model, or one of the default behaviour call backs, or be a standalone function.