Browse Source

Update Jsonable.md

Mark Sch 7 years ago
parent
commit
f6051286f7
1 changed files with 24 additions and 0 deletions
  1. 24 0
      docs/Behavior/Jsonable.md

+ 24 - 0
docs/Behavior/Jsonable.md

@@ -4,6 +4,30 @@ 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
 - Data can be of type array, params or list - or kept in JSON format
 - Additional sanitize functionality with "clean", "sort" and "unique
 - Additional sanitize functionality with "clean", "sort" and "unique
 
 
+## Important note
+Using 3.5+ you might not even need this anymore, as you can use type classes directly:
+```php
+    /**
+     * @param \Cake\Database\Schema\TableSchema $schema
+     *
+     * @return \Cake\Database\Schema\TableSchema
+     */
+    protected function _initializeSchema(TableSchema $schema)
+    {
+        $schema->columnType('my_field', 'json');
+
+        return $schema;
+    }
+```	
+This is best combined with the Shim.Json type, as it properly handles `null` values:
+```php
+// in bootstrap
+Type::map('json', 'Shim\Database\Type\JsonType');
+```
+
+But if you still need/want more flexible approaches, continue reading.
+
+
 ## Usage
 ## Usage
 Attach it to your model's `Table` class in its `initialize()` like so:
 Attach it to your model's `Table` class in its `initialize()` like so:
 ```php
 ```php