0

I put this function in my inc file

function getLanguage(){
  $url=url() ;
  $language="";
  $pos=strpos($url,"/es");
  if ($pos===false){
    $language="en";
  }else{
    $language="es";
  }
  return $language;
}

And then I try to call that function from the module, but the module says Fatal error: Call to undefined function getLanguage()

What am I doing wrong? thanks

4
  • Any files other than the .module file (exceptions are, the .install file and autoloaded classes) are not loaded unless you explicitly load them or specify the file location in the relevant hook. You can use module_load_include() to include the file before calling the function.
    – AKS
    Commented Oct 17, 2014 at 15:41
  • Where exactly would you put the module_load_include()? which part of the module?
    – user16839
    Commented Oct 17, 2014 at 16:42
  • I am now putting module_load_include('inc', 'mymodule', 'mymodule'); at the beginning of every function in the module, but isnt there some way to put it at the top of the module and not have to repeat it in every function?
    – user16839
    Commented Oct 17, 2014 at 17:21
  • You're understanding it the wrong way round, within the .module file you put your hooks and shared functions. Usually in the callbacks, you get to declare 'file' to point to an include for your functions to reside in a nice separate place. See api.drupal.org/api/drupal/modules%21system%21system.api.php/… and api.drupal.org/api/drupal/modules%21system%21system.api.php/…
    – Pobtastic
    Commented Oct 17, 2014 at 17:32

1 Answer 1

0

thank you pobtastic, this is the answer:

within the .module file you put your hooks and shared functions. Usually in the callbacks, you get to declare 'file' to point to an include for your functions to reside in a nice separate place. See api.drupal.org/api/drupal/modules%21system%21system.api.php/… and api.drupal.org/api/drupal/modules%21system%21system.api.php/… – Pobtastic 1 hour ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.