I have not seen this yet, but beans has a built-in method called getProperties() .
So, to use it:
// What bean do we want to get? $type = 'book'; $id = 13; // Load the bean $post = R::load($type,$id); // Get the properties $props = $post->getProperties(); // Print the JSON-encoded value print json_encode($props);
It is output:
{ "id": "13", "title": "Oliver Twist", "author": "Charles Dickens" }
Now take a step forward. If we have an array of beans ...
// An array of beans (just an example) $series = array($post,$post,$post);
... then we could do the following:
So this is ...
foreach ($series as &$val) { $val = $val->getProperties(); } print json_encode($series);
... outputs this:
[ { "id": "13", "title": "Oliver Twist", "author": "Charles Dickens" }, { "id": "13", "title": "Oliver Twist", "author": "Charles Dickens" }, { "id": "13", "title": "Oliver Twist", "author": "Charles Dickens" } ]
Hope this helps!
chrisfargen Jun 30 '13 at 18:03 2013-06-30 18:03
source share