如何在Drupal 7中定义模块级别的变量

har*_*adh 3 php variables drupal drupal-7

如何在drupal模块中定义变量,以便我可以从任何函数访问该模块中的那些变量

Muh*_*eda 5

尝试variable_set()和variable_get()

像这样设置变量:

// I have assumed the variable name to be "the_name_of_the_variable"
variable_set("the_name_of_the_variable", "the value of the variable");
Run Code Online (Sandbox Code Playgroud)

然后像这样检索值:

$my_variable = variable_get("the_name_of_the_variable", "a default value in case the variable has never been set before");
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助...穆罕默德。

  • variable_get / set的问题在于您将这些值存储在DB中,可能并非在所有情况下都需要这些值。 (2认同)