You can import an array into a bean using:
The code above is handy if your $_POST request array only contains book data. It will simply load all data into the book bean. You can also add a selection filter:
This will restrict the import to the fields specified. Note that this does not apply any form of validation to the bean. Validation rules have to be written in the model or the controller.
You can export the data inside a bean to an array like this:
$bookArray = $book->export();
Calling export() on a bean will export the data of a single bean into an array.
To recursively export one or an array of beans use:
$arrays = R::exportAll( $beans );
Bean lists in exports have keyless.
Both dup() and exportAll() need to query the database schema which is slow. To speed up the process you can pass a database schema:
To obtain the schema use:
$schema = R::$duplicationManager->getSchema();
You can now use this schema to feed it to setTables(). R::dup() and R::exportAll() both use this schema.
Since version 3.3: R::exportAll( $beans, true ) -- exports parent beans as well.
Since version 3.3: to only export a specific set of bean types: R::exportAll( $beans, true, $filters ); here $filters contains the list of types to be exported.
Import functions do not validate user input.
exportAll() is slow. You can speed up by passing an array of cache tables:
or export manually using the bean->export() functions.
It's very common in real life applications to swap properties. For instance, in a CMS you often have a feature to change the order of pages or menu items. To swap a property use:
$books = R::batch('book',array($id1,$id2));
We simply load two books using the batch loader, then we pass the array with two books to swap() as well as the name of the property we which to swap values of.
RedBeanPHP Easy ORM for PHP © 2013 Gabor de Mooij and the RedBeanPHP community - Licensed New BSD/GPLv2