ThinkPHP multi-language support and multi-template support Overview

Source: Internet
Author: User
This article mainly introduces ThinkPHP multi-language support and multi-template support. it is a very important technique for ThinkPHP. if you need ThinkPHP, refer to ThinkPHP.

This article describes ThinkPHP's multi-language support and multi-template support in the form of examples. ThinkPHP is a very important technique. I will share it with you for your reference. The details are as follows:

I. ThinkPHP multi-language support:

Add the following to the config. php configuration file:

// Set 'Lang _ SWITCH_ON '=> true, 'default _ lang' => 'zh-cn', 'Lang _ AUTO_DETECT' => true, 'Lang _ list' => 'en-us, zh-cn, zh-tw ',

Create three folders under the Home/Lang/folder, which are zh-cn, en-us, and zh-tw, which respectively represent simplified Chinese, English, and traditional Chinese.

You can create a file corresponding to the template or a public file common. php in the folder.

En-cn/common. php page:

<? Phpreturn array ('Welcome '=> 'hello', 'lan' => 'simplified Chinese',);?>

The en-us/common. php page is as follows:

<?phpreturn array( 'welcome'=>'how are you fine?', 'lan'=>'english', );?>

The zh-tw/common. php page is as follows:

<? Phpreturn array ('Welcome '=> 'hello', 'lan' => 'Welcome Chinese',);?>

The template index. php code is as follows:

Welcome: {$ Think. lang. welcome} language: {$ Think. lang. lan} simplified Chinese english traditional Chinese

Or you can directly define L ('demo', 'test') in the Action method. in this way, you can directly apply it in the template: {$ Think. lang. demo}
In the model, for example, array ('uname', 'require ', 'username mandatory'); can be used as follows: array ('uname', 'require ', '% name ');

II. support for multiple ThinkPHP templates:

Add the following to the config. php configuration file:

// Multiple templates support 'tmpl _ SWITCH_ON '=> true, 'tmpl _ DETECT_THEME' => true,

Create other skin folders under/Home/Tpl/, such as the red folder. the files in the folder are the same as those in the default file.

Add the following in the template file:

Red default

I believe the examples described in this article are helpful for ThinkPHP learning and development.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.