0

I have created a custom module 'sample'.I have created 'user_login' hook.I want to call a function 'calltype' within user_login hook but the function is not called.Cookie is created If I write the callType function code after the line $anivpopup = '1'; in user_login hook

function sample_user_login(&$edit, $account){
 $anivpopup = '1';
 callType();
}
function callType(){
 $anivpopup =1;
 if($anivpopup == '1'){
     setcookie('test', '2', time()+3600);  //cookie set for 1 hr
 }
}
user3386779
  • 6,883
  • 20
  • 66
  • 134
  • ? Why aren't you sending `$anivpopup` to the function `callType()` ??? – 2pha Aug 21 '17 at 09:51
  • Possible duplicate of [Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors?](https://stackoverflow.com/questions/16959576/reference-what-is-variable-scope-which-variables-are-accessible-from-where-and) – 2pha Aug 21 '17 at 09:53
  • noo need to pass the value.check my updated post.just given a sample code – user3386779 Aug 21 '17 at 10:17

2 Answers2

0

try this :

function sample_user_login(&$edit, $account){
  if(function_exists('callType'){
     callType();
  }else{
    die('Function callType does not declared');
  }
}

You must to know , drupal hook implementation is in cache so , on every modification made you have to clear registry cache

Fky
  • 2,133
  • 1
  • 15
  • 23
0

Try this.

function sample_user_login(&$edit, $account){
 $anivpopup = '1';
 callType($anivpopup);
}

function callType($anivpopup){
 if($anivpopup == '1'){
     setcookie('test', '2', time()+3600);  //cookie set for 1 hr
 }
}

Hope this helps you.

PraveenKumar
  • 1,851
  • 12
  • 18