search
Homephp教程php手册ThinkPHP的L方法使用简介

thinkPHP的L方法用于启用多语言的情况下,设置和获取当前的语言定义。这篇文章主要介绍了ThinkPHP的L方法使用简介,需要的朋友可以参考下

thinkPHP的L方法用于启用多语言的情况下,设置和获取当前的语言定义。
其调用格式为:L('语言变量'[,'语言值'])

1.设置语言变量

除了使用语言包定义语言变量之外,我们可以用L方法动态设置语言变量,,例如:

L('LANG_VAR','语言定义');

语言定义不区分大小写,所以下面也是等效的:

L('lang_var','语言定义');

不过规范起见,我们建议统一采用大写定义语言变量。

L方法支持批量设置语言变量,例如: $lang['lang_var1'] = '语言定义1'; $lang['lang_var2'] = '语言定义2'; $lang['lang_var3'] = '语言定义3'; L($lang);

表示同时设置3个语言变量lang_var1 lang_var2和lang_var3。

2.获取语言变量

$langVar = L('LANG_VAR');

或者:

$langVar = L('lang_var');

如果参数为空,表示获取当前定义的全部语言变量(包括语言定义文件中的):

$lang = L();

或者我们也可以在模板中使用

{$Think.lang.lang_var}

来输出语言定义。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools