In revo, it’s already done. If you’re using xPDO by itself, you’d pass into the config array:
XPDO_OPT_HYDRATE_FIELDS => true,
XPDO_OPT_HYDRATE_RELATED_OBJECTS => true,
XPDO_OPT_HYDRATE_ADHOC_FIELDS => true,
XPDO_OPT_HYDRATE_FIELDS:
Makes it so you can access fields straight instead of using get:
$chunk->get('description');
// becomes
$chunk->description;
Note: MODx recommends, however, to still use ->get(), since that allows for upgradability in the future.
XPDO_OPT_HYDRATE_RELATED_OBJECTS:
Allows you to directly access related objects when grabbed:
$profile = $user->getOne('modUserProfile');
$profile->get('email');
// becomes
$user->getOne('modUserProfile');
$user->modUserProfile->get('email');
XPDO_OPT_HYDRATE_ADHOC_FIELDS:
Allows you to hydrate adhoc (non-db-column) fields as well:
$user->set('test',1);
$t = $user->get('test');
// becomes
$user->set('test',1);
$t = $user->test;
How is this useful? Well, we still recommend using ->get() for things, since that allows us to easily override aliases later should we need to
However, templating engines like Smarty can use hydration to their benefit...like in the Revo manager:
In the controller:
$modx->smarty->assign('user',$user);
In the template:
Username: {$user->username}
Hope that helps.