I am working on a Drupal module,trying to get uname
and uid
of the global variable $user
: if $user
is used within .module file it works but if not I get : Trying to get property of non-object in ... on line 377
and var_dump($user)
gives null
,
here is my code :
MyModuleAPI.php:
function get_DB_Handler($projectname)
{
global $user;
$u_name = $user->name;
$u_id = $user->uid; //line 377
...
}
this function is called after an ajax POST query.
I will be grateful if someone clarify for me where is the difference since all files are in the same module. Any Help will be appreciated.