Install the plugin via Subversion
svn co http://svn.apostrophenow.org/plugins/DoctrineJSONColumnBehaviorPlugin/trunk plugins/DoctrineJSONColumnBehaviorPlugin
Enable the plugin in ProjectConfiguration
Enable the behavior for your models in schema.yml
Object:
actAs:
DoctrineJsonColumnTemplate:
fields: [api, params]
Build your model. If the columns using the behavior did not previously
exist it is also necessary to update your database.
New methods will now be added to your model to allow easy access and
modification of the columns stored as JSON.
$object = new Object();
$object->setApiParameter('name', 'Dan');
$object->save();
Doctrine:getTable('object')->find($object->id);
//Returns dan
$object->getApiParameter('name');
There are additional options that can be used to modify the behavior.
Object:
actAs:
JsonColumnTemplate:
fields: [api, params]
# Determines if json_encode should be called with assoc true,
# defaults to true.
assoc: true
# Modifies the methods used to get and set parameters inside JSON
# columns.
get_method_format: 'get%field%Parameter'
set_method_format: 'set%field%Parameter'