DoctrineJSONColumnBehaviorPlugin - 1.0

Allows for easy manipulation of Doctrine objects that store some objects as JSON.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

DoctrineJSONColumnBehaviorPlugin

The DoctrineJSONColumnBehaviorPlugin provides convenience methods for manipulating Doctrine columns stored as JSON.

Installation

  • 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'