|
|
@@ -4,7 +4,19 @@ A CakePHP behavior to automatically store nested data as JSON string and return
|
|
|
- Data can be of type array, params or list - or kept in JSON format
|
|
|
- Additional sanitize functionality with "clean", "sort" and "unique
|
|
|
|
|
|
-## Configs
|
|
|
+## Usage
|
|
|
+Attach it to your model's `Table` class in its `initialize()` like so:
|
|
|
+```php
|
|
|
+ $this->addBehavior('Tools.Jsonable', $options);
|
|
|
+```
|
|
|
+
|
|
|
+Tip: If you have other behaviors that might modify the array data prior to saving, better use a higher priority:
|
|
|
+```php
|
|
|
+$this->addBehavior('Tools.Jsonable', array('priority' => 11, ...));
|
|
|
+```
|
|
|
+So that it is run last.
|
|
|
+
|
|
|
+## Options
|
|
|
| Key | Default | Description |
|
|
|
| ------------- | ------------- | ------------- |
|
|
|
| fields | array() | Array of the fields to be converted |
|
|
|
@@ -22,18 +34,6 @@ A CakePHP behavior to automatically store nested data as JSON string and return
|
|
|
| decodeParams | | params for json_decode |
|
|
|
|
|
|
|
|
|
-## Usage
|
|
|
-Attach it to your models in `initialize()` like so:
|
|
|
-```php
|
|
|
-$this->addBehavior('Tools.Jsonable', $config);
|
|
|
-```
|
|
|
-
|
|
|
-Tip: If you have other behaviors that might modify the array data prior to saving, better use a higher priority:
|
|
|
-```php
|
|
|
-$this->addBehavior('Tools.Jsonable', array('priority' => 11, ...));
|
|
|
-```
|
|
|
-So that it is run last.
|
|
|
-
|
|
|
## Examples
|
|
|
|
|
|
The behavior supports different input/output formats:
|
|
|
@@ -120,4 +120,4 @@ Yes - you could make a new table/relation for this in the first place.
|
|
|
But sometimes it's just quicker to create such an enumeration field.
|
|
|
|
|
|
Bear in mind: It then cannot be sorted/searched by those values, though.
|
|
|
-For a more static solution take a look at my [Static Enums](http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/).
|
|
|
+For a more static solution take a look at my [Static Enums](http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/).
|