Home > Article > Backend Development > Introduction to the use of ThinkPHP's L method_PHP tutorial
thinkPHP’s L method is used to set and get the current language definition when multiple languages are enabled.
The calling format is: L('language variable'[,'language value'])
1. Set language variables
In addition to using language packages to define language variables, we can use the L method to dynamically set language variables, for example:
L('LANG_VAR','语言定义');
The language definition is not case-sensitive, so the following is also equivalent:
L('LANG_VAR','语言定义');
However, for the sake of standardization, we recommend that you use uppercase letters to define language variables.
L方法支持批量设置语言变量,例如: $lang['lang_var1'] = '语言定义1'; $lang['lang_var2'] = '语言定义2'; $lang['lang_var3'] = '语言定义3'; L($lang);
means setting three language variables lang_var1 lang_var2 and lang_var3 at the same time.
2. Get language variables
$langVar = L('LANG_VAR');
or:
$langVar = L('lang_var');
If the parameter is empty, it means to obtain all currently defined language variables (including those in the language definition file):
$lang = L();
Or we can also use
in the template
{$Think.lang.lang_var}
to output the language definition.