I think I'm using Redbean 3.3.7 (the all-in-one download from the website), but I can't find a version number in the code. I am receiving some json encoded data and want to process it with R::graph(), but I'm getting an error.
$json = '{"id": "","title": "Test Article","slug": "test-article","content": "<p>This is a test article</p>"}';
$decoded = json_decode($json, true);
This gives me an array
var_dump($decoded)
array(4) {
["id"]=>
string(0) ""
["title"]=>
string(12) "Test Article"
["slug"]=>
string(12) "test-article"
["content"]=>
string(29) "<p>This is a test article</p>"
}
Also
echo gettype($decoded);
returns "array".
But when I try this:
$bean = R::graph($decoded);
I get a RedBean_Exception_Security error with the message "Expected array but got :string"; rb.php line 9029
What am I doing wrong? And more importantly, how do I fix it?
Thanks.
According to the documentation "An array has to contain a key named 'type' containing the type of bean it represents". So I just had to add $decoded['type'] = 'table_name' before calling R::graph(). It also works if I add a hidden field named 'type' in the form I submit.
<input type="hidden" name="type" value="table_name" />