append data in user global variable?
Is ther开发者_JAVA技巧e any way that i can append my data into user global variable so i can access it on other pages?
You have two options
- You can save it on the user object (
$user->data
), if it's some static data that doesn't change. Use
hook_user
op load which could look like this:function module_user($op, &$edit, &$account, $category = NULL) { switch ($op) { case 'load': $account->module = db_fetch_object(db_query( 'SELECT * FROM {module} WHERE uid = %d', $account->uid )); break; } }
Hook user, is good if you have complex data that changes a lot. You can store the data in your own table, and append it you the user when it's being loaded. The downside is, that you will need to run user_load
you get the data on the user object.
If you don't need/want to handle the storage of your data in the database because you just want it the be globally accessible during the user's session, you can store it in the $_SESSION array.
You can also use variable_set() and variable_get()if the data is common to all users else SESSIONS need to be used
精彩评论