2008年8月29日

$user object (continute)

Drupal: Working With Users

Storing Data in the $user Object

The data field in the users table is for holding extra information in a serialized array. To store data, call user_save():

global $user;
$extra_data = array(’disposition’ => t(’Grumpy’));
user_save($user, $extra_data);

To retrieve data, do:

global $user;
print $user->disposition; //Prints ‘Grumpy’

This method creates additional overhead, because the data needs to be unserialized. An alternative method is to implement hook_user('load'), see below.

Adding Data to the $user Object

This can be done with hook_user('load').

沒有留言: