Mapping your object from an array

Simple usage

In its simplest form, this method takes an array of key=>values and map them to the object properties.</p>

Available options

The fromArray method accept an optional second parameter in the form of an array to alter its behavior. The following properties are available:</p>

Exemples on using the fromArray method in its simplest form</p>

$userArray = array(
    'id'=>34,
    'lastname'=>'my lastname',
    'firstname'=>'my firstname'
);
// initialize the user object
$user = new User();
$user->fromArray($userArray);
// persist the user object
$user->save();

Importing associations

Moreover, the fromArray method will preload the associations related to the object if it find the relevant keys corresponding to the one present in the field_meta configuration array. Be carefull to not overwrite your existing associations, or look at the 'load_assocations' option key describe below to enable/disable this feature.</p>

Exemples on using the fromArray method with associations:</p>

$fileArray = array(
    'id'=>56,
    'name'=>'my file',
    'users'=>'61,98'
);
$file = new File();
$file->fromArray($fileArray);
$file->save();
print_r($file);
/* will print:
File Object
(
    [meta_table] => Array
    (
        ...
    )
    [meta_fields] => Array
    (
        ...
    )
    [con] => Resource id #453
    [attributes] => Array
    (
        [name] => my name
    )
    [associations] => Array
    (
       [users] => Array
       (
           [0] => User Object
               (
             [meta_table] => Array
             (
                 ...
             )
             [meta_fields] => Array
             (
                 ...
             )
             [con] => Resource id #453
             [attributes] => Array
             (
                 ...
             )
             [associations] => Array
             (
                 ...
             )
         )
         [1] => User Object
         (
             [meta_table] => Array
             (
                 ...
             )
             [meta_fields] => Array
             (
             )
             [con] => Resource id #453
             [attributes] => Array
             (
                 ...
             )
             [associations] => Array
             (
                 ...
             )
         )
      )  
   )
)
*/