|
@@ -24,6 +24,24 @@ Attach it to your models in `initialize()` like so:
|
|
|
```php
|
|
```php
|
|
|
$this->addBehavior('Tools.Jsonable', $config);
|
|
$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:
|
|
|
|
|
+- "array" is the default input and output format
|
|
|
|
|
+- "list" is useful as some kind of pseudo enums or simple lists
|
|
|
|
|
+- "params" is useful for multiple key/value pairs
|
|
|
|
|
+- can be used to create dynamic forms (and tables)
|
|
|
|
|
+
|
|
|
|
|
+Also automatically cleans lists and works with custom separators/markup etc if you want it to.
|
|
|
|
|
+
|
|
|
|
|
+### Array
|
|
|
In my first scenario where I used it, I had a geocoder behavior attached to the model which returned an array.
|
|
In my first scenario where I used it, I had a geocoder behavior attached to the model which returned an array.
|
|
|
I wanted to save all the returned values, though, for debugging purposes in a field "debug".
|
|
I wanted to save all the returned values, though, for debugging purposes in a field "debug".
|
|
|
By using the following snippet I was able to do exactly that with a single line of config.
|
|
By using the following snippet I was able to do exactly that with a single line of config.
|
|
@@ -42,8 +60,6 @@ and leave the source field untouched for any later usage.
|
|
|
The same goes for the output: It will map the JSON content of "debug" back to the field "geocoder_result" as array, so
|
|
The same goes for the output: It will map the JSON content of "debug" back to the field "geocoder_result" as array, so
|
|
|
I have both types available then.
|
|
I have both types available then.
|
|
|
|
|
|
|
|
-## Examples
|
|
|
|
|
-
|
|
|
|
|
### Params
|
|
### Params
|
|
|
What if needed something more frontend suitable.
|
|
What if needed something more frontend suitable.
|
|
|
I want to be able to use a textarea field where I can put all kinds of params
|
|
I want to be able to use a textarea field where I can put all kinds of params
|