thinkphp Multi-language support and multi-template support Overview _php instance

Source: Internet
Author: User

In this paper, the thinkphp support and multiple template support are briefly described in the form of examples. Thinkphp is a very important skill to share with you for your reference. Specifically as follows:

First, thinkphp multi-language support:

config.php configuration file Add:

Multi-language support settings
' lang_switch_on ' =>true,
' Default_lang ' => ' zh-cn ',
' Lang_auto_detect ' =>true,
' Lang_list ' => ' en-us,zh-cn,zh-tw ',

home/lang/folder to create three folders, respectively, ZH-CN, en-US, ZH-TW, respectively, on behalf of Simplified Chinese, English, Traditional Chinese

Folders can be set up with the template corresponding to the file, or public files common.php

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

<?php return
Array (
 ' welcome ' => ' Hello ',
 ' lan ' => ' Simplified Chinese ' 
);
? >

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

<?php return
Array (
 ' welcome ' => ' How to Are you fine? ',
 ' LAN ' => ' 中文版 ' 
);
? >

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

<?php return
Array (
 ' welcome ' => ' Hello ',
 ' lan ' => ' Simplified Chinese ' 
);
? >

The template index.php code is as follows:

Welcome: {$Think. lang.welcome} language: {$Think. Lang.lan}
<a href= "? l=zh-cn" rel= "external nofollow" > Simplified Chinese </a>
<a href= "? l=en-us" rel= "external nofollow" >english</a> <a href= "? l=zh-tw" rel= "external
nofollow "> Chinese </a>

Or in the action method directly defined: L (' demo ', ' Test '), so that in the template can be directly applied: {$Think. Lang.demo}
For the model, for example: Array (' uname ', ' Require ', ' user name must be filled in '), can be used so: Array (' uname ', ' require ', '%name ');

Second, thinkphp Multi-template support:

config.php configuration file Add:

Multi-template Support
 ' tmpl_switch_on ' =>true,
 ' Tmpl_detect_theme ' =>true,

/home/tpl/Create other skin folders, such as Folder red, where the files are the same as in the default file.

To add in the template file:

<a href= "? t=red" rel= "external nofollow" > Red </a> <a href= "T=default" rel= "external nofollow
" > Default </a>

It is believed that the example mentioned in this article is helpful to thinkphp learning and developing.

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.