By adrian.mar on
Actually Im developing a system for reports management wich needs profile information in many system fases, for that Im using hook_user becouse when user is login in it loads some information in $user object, what I have is something like this, but Ive done test with direct information and dont happen nothing, somewhere can tell me whats wrong or how I can do this???? please
function squad_user($op, &$edit, &$account, $category = NULL) {
switch($op) {
case 'load':
$account->puesto = "EL NOMBRE DEL PUESTO (profile_puesto)";
$account->departamento = "EL NOMBRE DEL DEPARTAMENTO (profile_departamento)";
break;
}
}
Comments
help please
somebody cab help me ...
At first glance, that code
At first glance, that code looks fine. Some questions, and suggestions:
- which version of drupal?
- is your method being called at all? Suggest add: drupal_set_message("called squad_user($op)")
- how are you testing whether the information is being successfully added to $user? Suggest: print_r($user) in a block or similar. You may need to add "global $user" to make it visible first.
Answers
- The version of drupal is 5.7
- I done a print of my parameter using drupal_set_message and it looks right
- I have a content type named squad, and in its form "function squad_form(&$node)" I take the $user object information for display, but, dont appear $user->puesto and $user->departament, I suppose that this infomation was loaded on "function squad_user($op)"
I leave the code,
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------
Any suggest is truly grateful.
1) it's a little dangerous
1) it's a little dangerous to use $user as the parameter name here (because there is a global called $user, and it's easy to make mistakes accessing the wrong $user). I use $account as the parameter to hook_user
2) I wrote a module to test your code above, and had exactly the same problem! It appears that the issue is that user_load() (and hence hook_load) is not called for each page request: during a user session $user is constructed explicitly from querying {user} and {session} in the DB - so any change you make is not persisted. See http://drupal.org/node/49385 for another report.
I can only suggest that you call user_load explicitly whenever you care about this attribute. For example:
Hope this helps, Simon
thanks
thanks for your answer, it was an alternative method that is enought for my sistem :)
-------------------------------------------------------------------------------
I leave my final code if somebody has any doubt.